473,725 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

move_uploaded_f ile() 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.
Jul 16 '05 #1
5 7632

"neo002244" <ne*******@hotm ail.com> wrote in message
news:67******** *************** ***@posting.goo gle.com...
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.


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*******@hotm ail.com> wrote in message
news:67******** *************** **@posting.goog le.com...
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*******@hotm ail.com> wrote in message
news:67******** *************** ***@posting.goo gle.com...
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.


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*******@hotm ail.com> wrote in message
news:67******** *************** ***@posting.goo gle.com...
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*******@hotm ail.com> wrote in message
news:67******** *************** ***@posting.goo gle.com...
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
5175
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 work. I assumed it was a file path error, but after trying every possible file path combination, I dont think it is. I feel I have not done something to php or apache to handle moving files locally.
1
3015
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 it from /tmp. That's why I used move_uploaded_file() to move the file to /home/CUSTOMER/DOMAIN/tmp/FILENAME: ======================================================
6
3372
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 my IIS but refuses to work on the Apache. All I know is that the script stops working at move_uploaded_file() function. The warnings echo'ed are: Warning: move_uploaded_file(images/nieuws/TIDEEY%7E1.jpg): failed to open
4
2587
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 owner of folder and files, so later I cannot delete/rename/transfer those files trough winscp. Only load them if permissions are set ok. Chown doesn't work, because only superuser can change file's owner. What can I do? Make 24 h agreement with...
2
16296
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 I change it to 777 it does upload but the owner is www-data, but I then can't download it using a FTP client (which I have to do) as it's the wrong owner, so I have to leave the chomd as 755, but
5
3370
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 />"; } ------------------------ When I try to move the file using move_uploaded_file it fails. --------------
7
2080
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 and correct and i guess it loses the $file_temp var (actually the printout of $file_temp0 return nothing) i even tryed to write it repeating the parameters i/o using variables
4
21243
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 somewhere within the htdocs (server) folder. Here's the message: Warning: move_uploaded_file(C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/doc/images/clientpics/nurses.jpg) : failed to open stream: No such file or directory in...
0
1141
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
8889
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9179
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.