In another forum posting I requested help with code, to add to a script, that takes a file, after it's uploaded, and renames it with the logged-in users name (and keeps the same file extension) and moves it to a directory folder.
The code below does that successfully when added to the upload script.
I would like to modify this code so it renames uploaded files by combining the uploaded file name with the user name.
For example, Joe, the logged-in users name, uploads a file named MyLife.txt would be renamed MyLife Joe.txt.
Because this code (below) works successfully presently, I'd rather have someone help me modify it rather than provide all new code. Thank you. Any help would be greatly appreciated.
}
function upload_file($upload_directory, $upload_uri) {global $account;
$file_name = $_FILES["userfile"]["name"];
$file_name = str_replace(" ","_",$file_name);
$ext=pathinfo($file_name,PATHINFO_EXTENSION);
$file_path = $upload_directory.$account->get_user_name().'.'.$ext;
$temporary = $_FILES["userfile"]["tmp_name"];
$result = move_uploaded_file($temporary, $file_path);
if(!chmod($file_path,0777))
$message = "ERROR: A folder to place the files was not found, or the files need to be CHMODed to 777.";
else $message = ($result)?"File has been uploaded." : "An error has occurred.";
return $message;
}
p.s. the script uses $account->get_user_name(); to get the logged-in user name.





Bookmarks