Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

php - 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: enter image description here

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:

enter image description here

Thank you very much if anyone could help!!

question from:https://stackoverflow.com/questions/65598997/failed-to-open-stream-permission-denied-open-server

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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']);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...