简体   繁体   中英

failed to open stream: Permission denied open server

My aim is to download multiple files into the folder on my localhost. I am uploading them using the HTML form.

Here is the code (really sorry that I can't give a link to the executable version of the code because it relies on too many other files and database if anyone knows the way then please let me know)

foreach ($_FILES as $value) {
    $dir = '/';
    $filename = $dir.basename($value['name']);

    if (move_uploaded_file($value['tmp_name'],$filename)) {
        echo "File was uploaded";
        echo '<br>';
    }
    else {
        echo "Upload failed";
        echo '<br>';
    }
}

So this little piece of code give me an error: 在此处输入图像描述

And here are the lines of code:

The problem is that the adress is correct, I tried enterring it into my file directory and it worked fine, I have seen some adviced on other people's related questions that // or \ should be used instead, but my version works just fine: Also I have checked what's inside the $_FILES and here it is if that's required for someone trying to help:

在此处输入图像描述

Thank you very much if anyone could help!!

You are trying to move the file to an invalid (or non-existent) path. For the test you will write

 $dir = 'c:/existing_dir/';
 $filename = $dir.basename($value['name']);

If you want to move the file to a folder that is relative to the running file try

 $dir = '../../directory/';// '../' -> one directory back
 $filename = $dir.basename($value['name']);

By starting your file path with $dir = '/';you are saying store the file on the root folder, I assume of C:

Apache if correctly configures should not allow you access to C:\

So either do

$dir = '../';
$filename = $dir.basename($value['name']);

to make it a relative path or leave the $dir = '/'; out completely

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM