上传视频caUS $ _POST / $ _ FILES为空

时间:2016-08-27 06:57:47

标签: php html css file-upload

我正在尝试上传我的项目中的图片和视频,但是当我尝试上传视频时,它会为$_POST$_FILES返回一个空数组。 如果我尝试上传图片,相同的代码工作正常。我使用的代码如下:

extract($_POST);
$upload_dir = wp_upload_dir();
$target_dir = $upload_dir['basedir'].'/mediauploads/';
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

if($upd)
{
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    if($imageFileType != "mp4" && $imageFileType != "wmv" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg" && $imageFileType != "jpg")
    {
        echo "File Format Not Suppoted";
    } else {
        $video_path=$_FILES['fileToUpload']['name'];  
        move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file);
        echo "uploaded ";
    } 
}

上传视频表单:

<form method="post" enctype="multipart/form-data">

<table border="1" style="padding:10px">
    <tr>
        <Td>Upload  Video</td>
    </tr>

    <Tr>
        <td><input type="file" name="fileToUpload"/></td>
    </tr>

    <tr>
       <td><input type="submit" value="Uplaod Video" name="upd"/></td>
    </tr>
</table>
</form>

1 个答案:

答案 0 :(得分:0)

 if (isset($_FILES["stPic"]["name"]) && $_FILES["stPic"]["tmp_name"] != ""){
        $fileName = $_FILES["stPic"]["name"];
        $fileTmpLoc = $_FILES["stPic"]["tmp_name"];
        $fileType = $_FILES["stPic"]["type"];
        $fileSize = $_FILES["stPic"]["size"];
        $fileErrorMsg = $_FILES["stPic"]["error"];

     if (!preg_match("/.(gif|jpg|png|mp4|3gp|wmw|avi|mkv)$/i", $fileName) ) {
    echo "File Format Not Suppoted";
}else{
$moveResult = move_uploaded_file($fileTmpLoc, "video/$fileName");
if ($moveResult != true) {
        echo 'file not upload';
        exit();
    }
else{
//You run sql query 
echo 'Uploaded';
}


}
}