I am using this code when trying to upload a file into a directory:
if(move_uploaded_file($_FILES['upl']['tmp_name'], '../'.$acct_id.'/music/'.$playlist.'/'.$_FILES['upl']['name'])){
echo '{"status":"success"}';
exit;
}
It works fine as long as the $playlist variable is a single string (with no spaces)
But when the variable $playlist is something like "Greatest Hits" with the space between the two words, the code will not work?
I did try adding the rawurlencode($playlist) as suggested by a friend but still no luck:
if(move_uploaded_file($_FILES['upl']['tmp_name'], '../'.$acct_id.'/music/'.rawurlencode($playlist).'/'.$_FILES['upl']['name'])){
echo '{"status":"success"}';
exit;
}
I will try to explain a different way.
The problem in the string is with the $playlist variable, not the file name being uploaded.
It appears to me that your suggestion places the "rawurldecode" on the file name being uploaded.
The files that I am uploading do have spaces and they work fine as long as the $playlist has no spaces, so the problem is with the directory title which is being placed inside $playlist.
I have tried:
- htmlentities($playlist)
- urlencode($playlist)
- urldecode($playlist)
- rawurlencode($playlist)
- rawurldecode($playlist)
Does this make sense? Please help....
$_FILES['upl']['name']. It comes from the browser and a hacker might send you a carefully crafted request that could put the uploaded file in whatever directory they want it on your server. It's a big security issue.