473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

"not a valid JPEG file"

I am trying to upload an image to a server, but I get this warning:

Warning: imagecreatefromjpeg(): 'filename' is not a valid JPEG file

The error occurs when I am trying to create a thumbnail from the image. I
can subsequently display the JPG image itself, but the thumbnail creation
fails. I have tried this with hundreds of other images from the same source
and they work fine.

I have looked around on Google and it seems that others have had this same
problem, but I have not been able to find a solution.

Is this a PHP bug? Is there a workaround? Should I just trap the warning
and tell the user (my users will upload their own images) that the file is
not valid? They will surely question this, because seemingly every other
image displayer has no trouble with it.

--
Stephen Oakes
Jul 17 '05 #1
4 19312
Stephen Oakes wrote:

I am trying to upload an image to a server, but I get this warning:

Warning: imagecreatefromjpeg(): 'filename' is not a valid JPEG file

The error occurs when I am trying to create a thumbnail from the image. I
can subsequently display the JPG image itself, but the thumbnail creation
fails. I have tried this with hundreds of other images from the same source
and they work fine.

I have looked around on Google and it seems that others have had this same
problem, but I have not been able to find a solution.

Is this a PHP bug? Is there a workaround? Should I just trap the warning
and tell the user (my users will upload their own images) that the file is
not valid? They will surely question this, because seemingly every other
image displayer has no trouble with it.


Most image viewers know lots of image types. If the file is really a
renamed GIF/PNG/whatever the same viewer will be started because of the
extension, the viewer will recognize the real file type because of the
headers and view it. But imagecreatefromjpeg() will accept nothing but
jpegs.

Look at the first few bytes of the file in hex, you will most likely be
able to discern the real file type from them. If you are not able to do
so use a program that can identify image types from the content of the
file and not from the extension.

Bye!
Jul 17 '05 #2

"Anonymous" <an*******@nowhere.invalid> wrote...
I am trying to upload an image to a server, but I get this warning:

Warning: imagecreatefromjpeg(): 'filename' is not a valid JPEG file

The error occurs when I am trying to create a thumbnail from the image.
I
can subsequently display the JPG image itself, but the thumbnail creation
fails. I have tried this with hundreds of other images from the same
source
and they work fine.

I have looked around on Google and it seems that others have had this
same
problem, but I have not been able to find a solution.

Is this a PHP bug? Is there a workaround? Should I just trap the
warning
and tell the user (my users will upload their own images) that the file
is
not valid? They will surely question this, because seemingly every other
image displayer has no trouble with it.


Most image viewers know lots of image types. If the file is really a
renamed GIF/PNG/whatever the same viewer will be started because of the
extension, the viewer will recognize the real file type because of the
headers and view it. But imagecreatefromjpeg() will accept nothing but
jpegs.


It is a JPEG.

Any ideas?

--
Stephen Oakes
Jul 17 '05 #3

"Stephen Oakes" <so*****@XXXbigpond.net.au> wrote...
I am trying to upload an image to a server, but I get this warning:

Warning: imagecreatefromjpeg(): 'filename' is not a valid JPEG file


On further examination it appears that the file had not uploaded properly -
or perhaps was "slightly corrupt" to start with. Even though it can be
displayed by all image viewers (including Gimp, browsers, etc) it is
considered corrupt by PHP's imagecreatefromjpeg function.

--
Stephen Oakes
Jul 17 '05 #4
mwasif
802 Expert 512MB
Take a look at this http://bugs.php.net/bug.php?id=29878
Actually PHP is too picky about images. If it found a little problem with an image, it declares it as a corrupted image.
Jul 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ron Holmes | last post by:
I posted this question on the Crystal Reports Support site and I am still waiting for an answer. Using Crystal Reports 9.0 Developer Full edition: My Crystal report .RPT file has a Picture box...
72
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
2
by: Robin Tucker | last post by:
(note, this is a C# or VB.NET ambivalent question....) Hi, Have a slight problem with a library I'm using here (which I have the source code for). It has data files serialized with an...
0
by: Sam | last post by:
I'm wondering if I can pass variables to "TestForm.aspx" with the way I'm using it. It's acting as a jpeg image and looks like: <%@ Page ContentType="image/Jpeg" %> <%@ Import...
1
by: Kevin O`Brien | last post by:
I was reading my new asp.net book last night and thought I'd give mobile devices a go. I use Web Matrix, however when I went to create a new mobile page this morning, it displayed a dialog box...
21
by: cman | last post by:
does anyone know why i can't generate images with: header("Content-type:image/jpeg"); imagejpeg($img_number); i've tried different examples but i always get a text output as if the header...
4
by: Greg | last post by:
I've searched everywhere for a solution Microsoft .NET Framework V 2.0.50727 AutoEventWireup="false" image2.aspx resize an image on the fly but Page_Load is triggered twice: Any suggestion?...
12
by: Pao | last post by:
Hi all For all NEW sites (virtual directories) that I create, I receive always the same error: (I translate so may be a little different) Impossible to visualize the XML page Impossible to...
7
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have an image which I'm trying to save using my_image.Save(some_path, System.Drawing.Imaging.ImageFormat.Path); and then I get the error "Parameter is not valid". What could be the reason...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.