View Single Post

  #2 (permalink)  
Old 08-13-2003
Randell D.
 
Posts: n/a
Default Re: move_uploaded_file() corrupts some files


"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....


Reply With Quote