This is a discussion on move_uploaded_file() corrupts some files within the PHP Language forums, part of the PHP Programming Forums category; The move_uploaded_file() function is very quirky. I want to allow users to upload images to the Web site. Here is ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
The move_uploaded_file() function is very quirky. I want to allow
users to upload images to the Web site. Here is the code: if(!move_uploaded_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_file() 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_file() 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_file() 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. |
|
|||
|
"neo002244" <neo002244@hotmail.com> wrote in message news:6727e22f.0308121655.2a965ec2@posting.google.c om... > The move_uploaded_file() function is very quirky. I want to allow > users to upload images to the Web site. Here is the code: > > if(!move_uploaded_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_file() 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_file() 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_file() > 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. 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.... |
|
|||
|
"neo002244" <neo002244@hotmail.com> wrote in message news:6727e22f.0308130841.eb9e54a@posting.google.co m... > 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 news:<mmg_a.710445$3C2.16674954@news3.calgary.shaw .ca>... > > "neo002244" <neo002244@hotmail.com> wrote in message > > news:6727e22f.0308121655.2a965ec2@posting.google.c om... > > > The move_uploaded_file() function is very quirky. I want to allow > > > users to upload images to the Web site. Here is the code: > > > > > > if(!move_uploaded_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_file() 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_file() 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_file() > > > 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. > > > > 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.... 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)... |
|
|||
|
> 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)... 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. |
|
|||
|
"neo002244" <neo002244@hotmail.com> wrote in message news:6727e22f.0308131930.6c3858e6@posting.google.c om... > > 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)... > > 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. 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 |
|
|||
|
"neo002244" <neo002244@hotmail.com> wrote in message news:6727e22f.0308131930.6c3858e6@posting.google.c om... > > 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)... > > 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. 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 |