gpt4 book ai didi

php - 上传视频导致 $_POST/$_FILES 为空

转载 作者:行者123 更新时间:2023-11-28 05:18:43 24 4
gpt4 key购买 nike

我试图在我的元素中上传图片和视频,但是当我尝试上传视频时,它为 $_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>

最佳答案

 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';
}


}
}

关于php - 上传视频导致 $_POST/$_FILES 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39178383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com