"not a valid JPEG file"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Oakes

    "not a valid JPEG file"

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

    Warning: imagecreatefrom jpeg(): '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


  • Anonymous

    #2
    Re: "not a valid JPEG file"

    Stephen Oakes wrote:[color=blue]
    >
    > I am trying to upload an image to a server, but I get this warning:
    >
    > Warning: imagecreatefrom jpeg(): '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.[/color]

    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 imagecreatefrom jpeg() 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!

    Comment

    • Stephen Oakes

      #3
      Re: "not a valid JPEG file"


      "Anonymous" <anonymous@nowh ere.invalid> wrote...[color=blue][color=green]
      >> I am trying to upload an image to a server, but I get this warning:
      >>
      >> Warning: imagecreatefrom jpeg(): '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.[/color]
      >
      > 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 imagecreatefrom jpeg() will accept nothing but
      > jpegs.[/color]

      It is a JPEG.

      Any ideas?

      --
      Stephen Oakes


      Comment

      • Stephen Oakes

        #4
        Re: &quot;not a valid JPEG file&quot;


        "Stephen Oakes" <soakes1@XXXbig pond.net.au> wrote...[color=blue]
        >I am trying to upload an image to a server, but I get this warning:
        >
        > Warning: imagecreatefrom jpeg(): 'filename' is not a valid JPEG file[/color]

        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 imagecreatefrom jpeg function.

        --
        Stephen Oakes


        Comment

        • mwasif
          Recognized Expert Contributor
          • Jul 2006
          • 802

          #5
          Take a look at this http://bugs.php.net/bug.php?id=2987 8
          Actually PHP is too picky about images. If it found a little problem with an image, it declares it as a corrupted image.

          Comment

          Working...