I generally don't do PHP coding on Windows, but I've recently had to move one of the websites I administer to a Windows box. :queasy: I'm having trouble with the move_uploaded_file() function.

Here's the relevant code:

//$uploaddir = '/var/www/columbine/george/'; // when it was on Linux
$uploaddir = "D:\\\\WWWWEBS\\\\columbinechurchofchrist_org\\\\george\\\\";
$uploadfile = $uploaddir . $_FILES['userfile']['name'];

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
	print "Thanks!<br>File is valid, and was successfully uploaded. ";
} else {
        print "Possible file upload attack!  Here's some debugging info:\n";
        print_r($_FILES);
}

Here's the error message I'm getting:

PHP Warning: move_uploaded_file(D:\WWWWEBS\columbinechurchofchrist_org\george\temp.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\WWWWEBS\columbinechurchofchrist_org\admin\georgesfileuploads.php on line 25 PHP Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\php\uploadtemp\php7D.tmp' to 'D:\WWWWEBS\columbinechurchofchrist_org\george\temp.txt' in D:\WWWWEBS\columbinechurchofchrist_org\admin\georgesfileuploads.php on line 25

  1. PHP is not running in safe mode

  2. upload_tmp_dir is defined to be "D:\php\uploadtemp\" in php.ini

  3. The D:\WWWWEBS\columbinechurchofchrist_org\george\ directory exists

  4. Line 25 is the move_uploaded_file() line
    [/list=1]

    Here's what's printed by print_r:

    Possible file upload attack! Here's some debugging info: Array ( [userfile] => Array ( [name] => temp.txt [type] => text/plain [tmp_name] => D:\php\uploadtemp\php7D.tmp [error] => 0 [size] => 225 ) )

    Any ideas, anybody? I've searched all over for a solution to this but haven't really come up with anything. Help would be greatly appreciated.

    You need to set the proper permssiions on the following folder:

    D:\WWWWEBS\columbinechurchofchrist_org\admin\

      What sort of "proper permissions"? Also, 'admin' is just the folder that contains the upload script. The file is not being moved into that folder. It's supposed to be moved to 'george'.

        I copied the wrong line last time, you need to change the permissiosn on this folder:

        D:\WWWWEBS\columbinechurchofchrist_org\george)

        I can't tell you exactly how to set up your permissions since i don't know anything about the site, but whoever is to be uploading will need write permissions on that folder.

          Looks like the folder was set to 'read only'. I got the admin to change it.

          Thanks for the help! I appreciate it.

            Write a Reply...