0

I'm trying to upload files into separate folders based on the variable in the URI:

i.e.:

http://example.com/upload.php?name=john

// set specific folder uploads
$destFolder = $_GET['name'];


// success
if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$destFolder.'/'.$timestamp.'-'.$_FILES['upl']['name'])){
    echo '{"status":"success"}';
exit;
}

It uploads the file fine, but into "/uploads", not into "/uploads/john".

What am I overlooking? Thanks for looking.

5
  • I'de guess $destFolder is empty for some reason. Try logging that value and see what you get. Also, it is dangerous to use user input for specifying uploaded file destinations. Commented Jan 12, 2017 at 20:57
  • The folder exists and is writable. There will be only a few pre-existing folders. echo $_GET['name'] does return "john". Commented Jan 12, 2017 at 21:01
  • Possible duplicate of Move_uploaded_file() function is not working Commented Jan 12, 2017 at 21:07
  • can you output 'uploads/'.$destFolder.'/'.$timestamp.'-'.$_FILES['upl']['name'] ? Commented Jan 12, 2017 at 21:23
  • Yes, it outputs correctly, including my "john" subfolder. Commented Jan 12, 2017 at 21:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.