PHP: upload files to network shared folder

2019-05-26 16:27发布

问题:

I have a problem uploading file to a network shared folder. I can connect to the folder by using windows authentication in IE. The script is as followed:

$target_path =  '\\\\server\\images\\';
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

when i ran it , I got an error message read:

Warning: move_uploaded_file(\server\images\pic_firefox.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\xxxxxxxxx\uploader.php on line 6

I thought that's because windows authentication doesn't work this way. Is there a way I can upload the file by using username/password? Any thoughts would be appreciated.

回答1:

When you are running a PHP script from the browser, you are not running it under your user account. You are running under whatever the HTTP server uses as the user name. So even if you have access to the folder, the server may not. The easiest fix is to give the server write permission to that folder.