如何显示用户上传的视频

时间:2014-03-21 21:35:37

标签: php mysql

我有以下代码,但我想编辑它以便它询问用户标题和说明,然后他们上传文件,最后一旦提交它,它就会以缩略图的形式出现在页面上。

我不是要求有人为我做这件事,只是为了引导我朝着正确的方向前进。

代码:

<?
$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma");
$allowType = array("video/mp4","audio/mp3","audio/wma","image/png","image/gif","image/jpeg");
$maxSize = 20000000000000;
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$pathToUpload = 'upload/';

if (
    in_array($_FILES["file"]["type"], $allowType) &&
    in_array($extension, $allowedExts) &&
    $_FILES["file"]["size"] <= $maxSize
) {
    if ($_FILES["file"]["error"] > 0) {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    } else {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

        if (file_exists($pathToUpload . $_FILES["file"]["name"])) {
            echo $_FILES["file"]["name"] . " already exists. ";
        } else {
            move_uploaded_file($_FILES["file"]["tmp_name"], $pathToUpload . $_FILES["file"]["name"]);
            echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        }
    }
} else {
    echo "Invalid file";
}

1 个答案:

答案 0 :(得分:1)