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.

user888864
  • 25
  • 8
  • 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. – Michael Sacket Jan 12 '17 at 20:57
  • The folder exists and is writable. There will be only a few pre-existing folders. echo $_GET['name'] does return "john". – user888864 Jan 12 '17 at 21:01
  • Possible duplicate of [Move\_uploaded\_file() function is not working](http://stackoverflow.com/questions/18929178/move-uploaded-file-function-is-not-working) – newGuy Jan 12 '17 at 21:07
  • can you output `'uploads/'.$destFolder.'/'.$timestamp.'-'.$_FILES['upl']['name']` ? – harrrrrrry Jan 12 '17 at 21:23
  • Yes, it outputs correctly, including my "john" subfolder. – user888864 Jan 12 '17 at 21:29

0 Answers0