move_uploaded_file() corrupts some files

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

    move_uploaded_file() corrupts some files

    The move_uploaded_f ile() function is very quirky. I want to allow
    users to upload images to the Web site. Here is the code:

    if(!move_upload ed_file($_FILES['tempimagefile']['tmp_name'],
    $imagefile))
    {
    die("Could not move file: ".$_FILES['tempimagefile']['tmp_name']."
    -> $imagefile");
    } else {
    enter record into database...
    ...
    ...
    }

    The record is added to the database, so I have to assume that the
    move_uploaded_f ile() function returned a positive result. Elsewhere in
    the Web site I have a function that displays the image. The
    getimagesize() function is used to determine the image dimensions. I
    get an error message when the move_uploaded_f ile() function had
    corrupted the file upload:

    Warning: getimagesize(): Read error! ...
    Could not get size of: imagename.gif

    The file exists but its size is 0 bytes. Somehow the image data is
    non-existent. Only an empty file with the correct file name is
    present. This causes the getimagesize() function to spew out that
    error message. Is this a known issue with the move_uploaded_f ile()
    function? I've read somewhere else that using the copy() function
    results in the same thing - a corrupt file. Does anyone know why this
    is happening? Is there any way to fix this problem? Thanks.
  • Randell D.

    #2
    Re: move_uploaded_f ile() corrupts some files


    "neo002244" <neo002244@hotm ail.com> wrote in message
    news:6727e22f.0 308121655.2a965 ec2@posting.goo gle.com...[color=blue]
    > The move_uploaded_f ile() function is very quirky. I want to allow
    > users to upload images to the Web site. Here is the code:
    >
    > if(!move_upload ed_file($_FILES['tempimagefile']['tmp_name'],
    > $imagefile))
    > {
    > die("Could not move file: ".$_FILES['tempimagefile']['tmp_name']."
    > -> $imagefile");
    > } else {
    > enter record into database...
    > ...
    > ...
    > }
    >
    > The record is added to the database, so I have to assume that the
    > move_uploaded_f ile() function returned a positive result. Elsewhere in
    > the Web site I have a function that displays the image. The
    > getimagesize() function is used to determine the image dimensions. I
    > get an error message when the move_uploaded_f ile() function had
    > corrupted the file upload:
    >
    > Warning: getimagesize(): Read error! ...
    > Could not get size of: imagename.gif
    >
    > The file exists but its size is 0 bytes. Somehow the image data is
    > non-existent. Only an empty file with the correct file name is
    > present. This causes the getimagesize() function to spew out that
    > error message. Is this a known issue with the move_uploaded_f ile()
    > function? I've read somewhere else that using the copy() function
    > results in the same thing - a corrupt file. Does anyone know why this
    > is happening? Is there any way to fix this problem? Thanks.[/color]

    Are you storing the image as a disk file on disk or in your database? (your
    conditional statement above says, after moving the image from tmp to
    $imagefile you have something about 'enter record into database')... I'm
    wondering if you're attempting to read the image from the db and that could
    be the source of your problem.

    I've never had problems uploading files of anysize (up to four or five
    megabytes in size - perhaps larger). One are I did have problems though was
    when I tested an upload from remote, I found my Linksys router that I use as
    a firewall screwed up the file in transit (I've still not resolved this
    problem). Files less than a meg were fine - anything larger were
    unzippable/unreadable/undoable.

    Dunno if that helps you out in anyway....


    Comment

    • Randell D.

      #3
      Re: move_uploaded_f ile() corrupts some files


      "neo002244" <neo002244@hotm ail.com> wrote in message
      news:6727e22f.0 308130841.eb9e5 4a@posting.goog le.com...[color=blue]
      > Randall,
      >
      > Thanks for the reply. I am only putting the location of the image in
      > the database and not the image itself. I've noticed that only gif
      > images get corrupted, not jpegs. Isn't this strange behavior?
      >
      > "Randell D." <you.can.email. me.at.randelld@ yahoo.com> wrote in message[/color]
      news:<mmg_a.710 445$3C2.1667495 4@news3.calgary .shaw.ca>...[color=blue][color=green]
      > > "neo002244" <neo002244@hotm ail.com> wrote in message
      > > news:6727e22f.0 308121655.2a965 ec2@posting.goo gle.com...[color=darkred]
      > > > The move_uploaded_f ile() function is very quirky. I want to allow
      > > > users to upload images to the Web site. Here is the code:
      > > >
      > > > if(!move_upload ed_file($_FILES['tempimagefile']['tmp_name'],
      > > > $imagefile))
      > > > {
      > > > die("Could not move file: ".$_FILES['tempimagefile']['tmp_name']."
      > > > -> $imagefile");
      > > > } else {
      > > > enter record into database...
      > > > ...
      > > > ...
      > > > }
      > > >
      > > > The record is added to the database, so I have to assume that the
      > > > move_uploaded_f ile() function returned a positive result. Elsewhere in
      > > > the Web site I have a function that displays the image. The
      > > > getimagesize() function is used to determine the image dimensions. I
      > > > get an error message when the move_uploaded_f ile() function had
      > > > corrupted the file upload:
      > > >
      > > > Warning: getimagesize(): Read error! ...
      > > > Could not get size of: imagename.gif
      > > >
      > > > The file exists but its size is 0 bytes. Somehow the image data is
      > > > non-existent. Only an empty file with the correct file name is
      > > > present. This causes the getimagesize() function to spew out that
      > > > error message. Is this a known issue with the move_uploaded_f ile()
      > > > function? I've read somewhere else that using the copy() function
      > > > results in the same thing - a corrupt file. Does anyone know why this
      > > > is happening? Is there any way to fix this problem? Thanks.[/color]
      > >
      > > Are you storing the image as a disk file on disk or in your database?[/color][/color]
      (your[color=blue][color=green]
      > > conditional statement above says, after moving the image from tmp to
      > > $imagefile you have something about 'enter record into database')... I'm
      > > wondering if you're attempting to read the image from the db and that[/color][/color]
      could[color=blue][color=green]
      > > be the source of your problem.
      > >
      > > I've never had problems uploading files of anysize (up to four or five
      > > megabytes in size - perhaps larger). One are I did have problems though[/color][/color]
      was[color=blue][color=green]
      > > when I tested an upload from remote, I found my Linksys router that I[/color][/color]
      use as[color=blue][color=green]
      > > a firewall screwed up the file in transit (I've still not resolved this
      > > problem). Files less than a meg were fine - anything larger were
      > > unzippable/unreadable/undoable.
      > >
      > > Dunno if that helps you out in anyway....[/color][/color]


      Someone in this newsgroup suggested that you should always reply to a post
      by replying at the end of it - it makes it easier for others to read the
      history by starting from the top (oldest thread) and paging down to the
      newest thread... Just a suggestion, hope you don't mind...

      anyway... its interesting that you say that you found the problem only
      occurs for gifs and not jpgs - I'm wondering if you have a filesystem
      problem - That might sound crazy but I've got the bones of about 2,500
      images that I've saved over time - I burned them to disk and found I could
      only read the jpgs - not the gifs... I then ftp'd the images from my linux
      server to my windoze box and found again that I could not view the gifs
      (though I had some of the originals on my windoze box and they could be
      viewed so I could be sure the problem did not originate on my windoze box).

      I've yet to find out the cause for this - but I suggest you try and ftp a
      handful of images to your box and then try and view them... see if you get
      the same problems and thus rule out the apache/php as the source of your
      problem.

      and just in case... I'm running SuSE Linux 7.1, kernal 2.4.0-4Gb (about a
      year or more old)...


      Comment

      • neo002244

        #4
        Re: move_uploaded_f ile() corrupts some files

        > Someone in this newsgroup suggested that you should always reply to a post[color=blue]
        > by replying at the end of it - it makes it easier for others to read the
        > history by starting from the top (oldest thread) and paging down to the
        > newest thread... Just a suggestion, hope you don't mind...
        >
        > anyway... its interesting that you say that you found the problem only
        > occurs for gifs and not jpgs - I'm wondering if you have a filesystem
        > problem - That might sound crazy but I've got the bones of about 2,500
        > images that I've saved over time - I burned them to disk and found I could
        > only read the jpgs - not the gifs... I then ftp'd the images from my linux
        > server to my windoze box and found again that I could not view the gifs
        > (though I had some of the originals on my windoze box and they could be
        > viewed so I could be sure the problem did not originate on my windoze box).
        >
        > I've yet to find out the cause for this - but I suggest you try and ftp a
        > handful of images to your box and then try and view them... see if you get
        > the same problems and thus rule out the apache/php as the source of your
        > problem.
        >
        > and just in case... I'm running SuSE Linux 7.1, kernal 2.4.0-4Gb (about a
        > year or more old)...[/color]

        Randall,

        It seems that there are some issues with GIFs when you transfer them
        from Windows to Linux. I FTPed the corrupted GIF file to Windows and I
        couldn't view it. I would think that there has to be someone out there
        who has had GIF issues with Linux. I hope to resolve this issue in the
        near future. In the meantime, I am amazed at the fact that I can't
        seem to find more info concerning this problem.

        Comment

        • Randell D.

          #5
          Re: move_uploaded_f ile() corrupts some files


          "neo002244" <neo002244@hotm ail.com> wrote in message
          news:6727e22f.0 308131930.6c385 8e6@posting.goo gle.com...[color=blue][color=green]
          > > Someone in this newsgroup suggested that you should always reply to a[/color][/color]
          post[color=blue][color=green]
          > > by replying at the end of it - it makes it easier for others to read the
          > > history by starting from the top (oldest thread) and paging down to the
          > > newest thread... Just a suggestion, hope you don't mind...
          > >
          > > anyway... its interesting that you say that you found the problem only
          > > occurs for gifs and not jpgs - I'm wondering if you have a filesystem
          > > problem - That might sound crazy but I've got the bones of about 2,500
          > > images that I've saved over time - I burned them to disk and found I[/color][/color]
          could[color=blue][color=green]
          > > only read the jpgs - not the gifs... I then ftp'd the images from my[/color][/color]
          linux[color=blue][color=green]
          > > server to my windoze box and found again that I could not view the gifs
          > > (though I had some of the originals on my windoze box and they could be
          > > viewed so I could be sure the problem did not originate on my windoze[/color][/color]
          box).[color=blue][color=green]
          > >
          > > I've yet to find out the cause for this - but I suggest you try and ftp[/color][/color]
          a[color=blue][color=green]
          > > handful of images to your box and then try and view them... see if you[/color][/color]
          get[color=blue][color=green]
          > > the same problems and thus rule out the apache/php as the source of your
          > > problem.
          > >
          > > and just in case... I'm running SuSE Linux 7.1, kernal 2.4.0-4Gb (about[/color][/color]
          a[color=blue][color=green]
          > > year or more old)...[/color]
          >
          > Randall,
          >
          > It seems that there are some issues with GIFs when you transfer them
          > from Windows to Linux. I FTPed the corrupted GIF file to Windows and I
          > couldn't view it. I would think that there has to be someone out there
          > who has had GIF issues with Linux. I hope to resolve this issue in the
          > near future. In the meantime, I am amazed at the fact that I can't
          > seem to find more info concerning this problem.[/color]

          True... It might be worth while making a post in one of the linux ng's - in
          addition, I don't know if you know but officially, the license (or the
          alogritm used) to make GIF files is owned by Unisys hence the reason why the
          GD graphics library, among others, have dropped support and instead moved to
          PNG type files (which are supposed to offer better compression in addition
          to all the other advantages of a GIF file).

          I'm glad that you've at least replicated the problem via ftp which should
          therefore rule out PHP from being the culprit... If you make a post in one
          of the linux ng's I think you will eventually find the answer - if not, I'll
          drop you a byte if I find out but at the moment its low priority on my todo
          list since I'm pretty sure the problem is external to PHP...

          cheers
          randelld


          Comment

          • Randell D.

            #6
            Re: move_uploaded_f ile() corrupts some files


            "neo002244" <neo002244@hotm ail.com> wrote in message
            news:6727e22f.0 308131930.6c385 8e6@posting.goo gle.com...[color=blue][color=green]
            > > Someone in this newsgroup suggested that you should always reply to a[/color][/color]
            post[color=blue][color=green]
            > > by replying at the end of it - it makes it easier for others to read the
            > > history by starting from the top (oldest thread) and paging down to the
            > > newest thread... Just a suggestion, hope you don't mind...
            > >
            > > anyway... its interesting that you say that you found the problem only
            > > occurs for gifs and not jpgs - I'm wondering if you have a filesystem
            > > problem - That might sound crazy but I've got the bones of about 2,500
            > > images that I've saved over time - I burned them to disk and found I[/color][/color]
            could[color=blue][color=green]
            > > only read the jpgs - not the gifs... I then ftp'd the images from my[/color][/color]
            linux[color=blue][color=green]
            > > server to my windoze box and found again that I could not view the gifs
            > > (though I had some of the originals on my windoze box and they could be
            > > viewed so I could be sure the problem did not originate on my windoze[/color][/color]
            box).[color=blue][color=green]
            > >
            > > I've yet to find out the cause for this - but I suggest you try and ftp[/color][/color]
            a[color=blue][color=green]
            > > handful of images to your box and then try and view them... see if you[/color][/color]
            get[color=blue][color=green]
            > > the same problems and thus rule out the apache/php as the source of your
            > > problem.
            > >
            > > and just in case... I'm running SuSE Linux 7.1, kernal 2.4.0-4Gb (about[/color][/color]
            a[color=blue][color=green]
            > > year or more old)...[/color]
            >
            > Randall,
            >
            > It seems that there are some issues with GIFs when you transfer them
            > from Windows to Linux. I FTPed the corrupted GIF file to Windows and I
            > couldn't view it. I would think that there has to be someone out there
            > who has had GIF issues with Linux. I hope to resolve this issue in the
            > near future. In the meantime, I am amazed at the fact that I can't
            > seem to find more info concerning this problem.[/color]

            Oh! One thing - If you do post to one of the linux newsgroups - don't forget
            to specify your flavour of Unix/Linux and what type of filesystem you are
            storing your data on (in case it is filesystem related)... if you're unsure
            on how to tell all this, then a uname -a from the root command prompt and
            copy/paste the output to your post - in addition, examine your /etc/fstab
            for the filesystem that you keep your gifs on, and the filesystem type
            should be the third or fourth entry/word (space delimited). All of this
            will help someone out there point you in the right direction.

            cheers again,
            randelld


            Comment

            Working...