2016-11-09 154 views
0
<?php 
$target_dir = "uploads/"; 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
$uploadOk = 1; 
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
// Check if image file is a actual image or fake image 
if(isset($_POST["submit"])) { 
    if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg"){ 
    echo "File is not an image."; 
     $uploadOk = 0; 
    } else { 
     echo "File is an image "; 
     $uploadOk = 1; 
    } 
} 
// Check if $uploadOk is set to 0 by an error 
if ($uploadOk == 0) { 
    echo "Sorry, your file was not uploaded.1"; 
// if everything is ok, try to upload file 
} else { 
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
     echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
    } else { 
     echo "Sorry, there was an error uploading your file."; 
    } 
} 
?> 

看起來像一切都寫好了,但腳本不工作,因爲它應該。試圖上傳MP4,MPEG和所有其他格式。它上傳jpeg,torrent文件但拒絕上傳視頻文件爲什麼?我在Windows上運行XAMP。問題在哪裏?上傳視頻文件時,PHP文件上傳表單不起作用

+3

這可能是默認的max_size_upload限制問題PHP是2MB –

+1

注意,使用'PATHINFO()'來確定一個文件的類型是非常可疑的。它執行字符串操作,而不分析文件實際包含的數據類型。 – arkascha

回答

1

發現我自己的答案,需要編輯php.ini文件:

; Maximum allowed size for uploaded files. 
upload_max_filesize = 40M 

; Must be greater than or equal to upload_max_filesize 
post_max_size = 40M