File Upload Problems 
Author Message
 File Upload Problems

Hi All,

I'm trying to develop a simple file upload component in a project I am
working on. Everything *seems* to work ok; the filename, mime type and
file size are reported correctly, but no file is actually uploaded. I
get the feeling that this is something to do with the system set up.
This is on a Win 2K box, but the project is eventually destined for a
Mac OS X box, where it has been tested and the same problem occurs.

Can anyone point me in the right direction?

tia,

Chris

code follows:

HTML form

<form  enctype="multipart/form-data" method="post" action="<? echo
$PHP_SELF?>">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
<input name="userfile" type="file">
<input type="submit" name="Submit1" value="Upload">
</form>

PHP processing

if($_FILES['userfile']['name']){
        $ufile = $_FILES['userfile']['name'];
        $ftype = $_FILES['userfile']['type'];
        $fsize = $_FILES['userfile']['size'];
        //get userdir
        $sql = "select Directory from users where UID = $uid";
        $result = mysql_query($sql,$db);
        if($row = mysql_fetch_array($result)){
                do{
                        $dirname = $row["Directory"];
                }while($row = mysql_fetch_array($result));
        }
        $path = "./user_files/" . $dirname;
        move_uploaded_file($ufile, $path);
        $fileref = $path . "/" . $ufile;
        $sql = "insert into resources
(User_ID,Path_ID,Note_ID,Res_loc,Res_type,Res_size) values
($uid,$pid,$nid,'$fileref','$ftype','$fsize')";
        $result = mysql_query($sql,$db);

Quote:
}



Fri, 05 Aug 2005 18:30:48 GMT  
 File Upload Problems

Quote:

> I'm trying to develop a simple file upload component in a project I am
> working on. Everything *seems* to work ok; the filename, mime type and
> file size are reported correctly, but no file is actually uploaded. I
> get the feeling that this is something to do with the system set up.
> This is on a Win 2K box, but the project is eventually destined for a
> Mac OS X box, where it has been tested and the same problem occurs.

> Can anyone point me in the right direction?

> PHP processing

> if($_FILES['userfile']['name']){
> $ufile = $_FILES['userfile']['name'];

** $_FILES['userfile']['name'] is the name of the file as it exists on the
client's machine! To get the file on the server:

$rfile = $_FILES['userfile']['tmp_name'];

And change this

Quote:
> move_uploaded_file($ufile, $path);

to:
move_uploaded_file($rfile, $path."/".$ufile);

Additionally you can check move_uploaded_file() as it returns FALSE on
error, e.g.

if(move_uploaded_file($rfile, $path."/".$ufile){
    // proceed...

Quote:
}

Hope this helps;
JOn


Fri, 05 Aug 2005 18:47:53 GMT  
 File Upload Problems


Quote:
>** $_FILES['userfile']['name'] is the name of the file as it exists on the
>client's machine! To get the file on the server:

>$rfile = $_FILES['userfile']['tmp_name'];

>And change this
>> move_uploaded_file($ufile, $path);
>to:
>move_uploaded_file($rfile, $path."/".$ufile);

Thanks Jon, that's solved it. I can't believe i was staring at this
for so long and it turns out to be something so simple *slaps
forehead*.

Thanks again,

C



Sat, 06 Aug 2005 00:01:06 GMT  
 File Upload Problems

Quote:

> I'm trying to develop a simple file upload component in a project I am
> working on. Everything *seems* to work ok; the filename, mime type and
> file size are reported correctly, but no file is actually uploaded. I
> get the feeling that this is something to do with the system set up.
> This is on a Win 2K box, but the project is eventually destined for a
> Mac OS X box, where it has been tested and the same problem occurs.

> Can anyone point me in the right direction?

Looks like someone else on this thread just did.

Linux/Unix users should also note that some distributors (e.g. Red Hat) now
have changed the layout of configuration-files for PHP and/or Apache, using
"include" files.  You can easily overlook the existence of these files, and
thus not realize some of the settings that are being picked up.

For example, the latest Red Hat distributions "helpfully" impose a limit on
upload-file size of about 800K using such methods.  I "discovered" this
(the hard way) when image-file uploads {several megabytes each} stopped
working.  It turns out that Apache/PHP were in fact doing exactly as they
had been told, but I didn't know they'd been told it.  I searched for the
configuration-file settings that were supposed to control this and couldn't
find them ... because I didn't realize at the time that there were
includes.  A global "grep" of the "/etc" directory (!!) finally gave me a
clue.  As did google, of course.

Maybe this will save someone a flat forehead.  {<Slap!> "Doh!!"}  ;-)

----------------------------------
Fast automatic Paradox/Delphi table repair at a click of a mouse!
http://www.sundialservices.com/products/chimneysweep



Sat, 06 Aug 2005 00:58:22 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. File Upload Problems with binary files (ASCII works ok)

2. file upload-problem: my computer sometimes blocks

3. file upload problem

4. PHP Expert needs help with file upload problem: permission denied

5. NEWBIE: File upload problems

6. file upload problem

7. Q: File Upload Problem

8. Yet another file upload problem

9. Uploading Data from BASIC file Problem

10. file size upload problem

11. Problem while uploading a binary file using cgi module

12. Problem with file upload

 

 
Powered by phpBB® Forum Software