提问者:小点点

php在上传文件名之前在文件名的开头添加字符串变量[重复]


假设我有一个会话变量

$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


共1个答案

匿名用户

上传前否,但保存时是:

 $path = "../videos/";
 $path .=  $username.basename($_FILES['uploaded_file']['name']);

相关问题