我的客户端需要文件名与上传时的名称相同。但我需要将所有文件存储在同一个文件夹中。怎么样?或者处理这个问题的最佳方法是什么,这样我就可以让客户端以他上传的名字下载文件。
答案 0 :(得分:0)
试试这个:
$randString = md5(time()); //encode the timestamp - returns a 32 chars long string
$fileName = $_FILES["uploaded_file"]["name"]; //the original file name
$splitName = explode(".", $fileName); //split the file name by the dot
$fileExt = end($splitName); //get the file extension
$newFileName = strtolower($randString.'.'.$fileExt); //join file name and ext.
答案 1 :(得分:-1)
$name = "foto";
$extension = ".png";
$today = date("Y/m/d-H:i:s");
$fullName = $name."_".$today.$fileExtension;
//where $name was it's actual name
//$today is todays date and time
//$file extension would be something like ".png"
$fullName
的值示例为foto_2001/03/10-17:16:18.png