假设我有一个会话变量
$username=$_SESSION['userUid'];
我可以在上传之前将其作为字符串添加到文件名中吗?
if (!empty($_FILES['uploaded_file'])) {
$allowed = array("video/mp4", "video/webm", "video/ogg");//Allowed types
$file_type = $_FILES['uploaded_file']['type'];
$path = "../videos/";
$path = $path . basename($_FILES['uploaded_file']['name']);
if (!in_array($file_type, $allowed)) {
header("location:../add-video.php?lesson=" . $lesson . "&alert=wrongtype");
}
if (file_exists($path)) {
header("location:../add-video.php?lesson=" . $lesson . "&alert=alreadyexist");
} elseif (in_array($file_type, $allowed) && !file_exists($path)) {
move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path);
echo "The file " . basename($_FILES['uploaded_file']['name']) .
" has been uploaded"; // if checks are successful upload the file
所以在视频目录中,我会有这样的东西:uer345video.mp4
上传前否,但保存时是:
$path = "../videos/";
$path .= $username.basename($_FILES['uploaded_file']['name']);