473,398 Members | 2,212 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,398 software developers and data experts.

move_uploaded_file() corrupts some files

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.
Jul 16 '05 #1
5 7556

"neo002244" <ne*******@hotmail.com> wrote in message
news:67**************************@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....
Jul 16 '05 #2

"neo002244" <ne*******@hotmail.com> wrote in message
news:67*************************@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." <yo**************************@yahoo.com> wrote in message

news:<mm***********************@news3.calgary.shaw .ca>...
"neo002244" <ne*******@hotmail.com> wrote in message
news:67**************************@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)...
Jul 16 '05 #3
> 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.
Jul 16 '05 #4

"neo002244" <ne*******@hotmail.com> wrote in message
news:67**************************@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
Jul 16 '05 #5

"neo002244" <ne*******@hotmail.com> wrote in message
news:67**************************@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
Jul 16 '05 #6

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

Similar topics

1
by: Paul Lamonby | last post by:
Hi, I am using Mac os10.3.3, running Apache and PHP 4.3.6 I am just starting to use my local Sites folder to test php for my sites, but I cannot seem to get move_uploaded_file() or copy() to...
1
by: Felix Natter | last post by:
hi, I would like to upload a file (via a form), then read that (temporary) file and write the contents into a database. The first problem is that open_basedir=/home/CUSTOMER so I can't just read...
6
by: Stijn Goris | last post by:
HI all, I have created a script that allows a user to upload a picture. I have an IIS server runing on my own pc but the actual site runs an Apache server. The upload script worked perfectly on...
4
by: Perttu Pulkkinen | last post by:
I have a form handler script that creates a new folder for the files sent in the form. Move_uploaded_file transfers then puts those files there. But problem is that apache becomes automaticly...
2
by: Brian | last post by:
Hi I am moving a site to a new server, I have been testing it and one of the pages uses move_uploaded_file, but I get a Permission denied. The directory I am moving it to is chomd of 755, if...
5
by: bill | last post by:
I can validate that the file uploaded because is_uploaded_file() returns true. --------- if (is_uploaded_file($_FILES)) { echo "File ". $_FILES ." uploaded successfully.<br />"; }...
7
by: nicemotion | last post by:
Hi all, the following easy script correctly insert a record in the DB but is not moving the images (Logo and Foto) to the server /foto folder. can't understand why 'cause the script is easy...
4
ifedi
by: ifedi | last post by:
In testing out a file upload script on my developer machine, I repeatedly came up with an error message. The goal was to upload pictures from a registration form into the folder 'clientpics' located...
0
by: 99levelsofundo | last post by:
hi (new here) - i'm using a simple file upload function from an swf calling an upload.php file with: <?php $fileName = $_GET; $path = "temp/"; move_uploaded_file($_FILES,$path.$fileName);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.