Solution 1 :

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

Solution 2 :

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

Problem :

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!!


Comment posted by RiggsFolly

We dont need a picture of code ever, but definitely not when you have posted the code as text anyway