2014-06-23 109 views
2

我可以使用PHP上传脚本上传png/jpegs/images,但无法在本地服务器上传mp4文件。脚本不显示任何错误。使用PHP上传mp4文件

<?php 
ini_set('display_startup_errors',1); 
ini_set('display_errors',1); 
error_reporting(-1); 
//include authentication here/ Gmail is good solution for now 
//check if it's not allowing any other extenstion other than MP4 
$allowedExts = array("gif", "jpeg", "jpg", "png","mp4"); 
$temp = explode(".", $_FILES["file"]["name"]); 
print_r($_FILES["file"]["type"]); 
$extension = end($temp); 
if ((($_FILES["file"]["type"] == "image/gif") 
|| ($_FILES["file"]["type"] == "image/jpeg") 
|| ($_FILES["file"]["type"] == "image/jpg") 
|| ($_FILES["file"]["type"] == "image/pjpeg") 
|| ($_FILES["file"]["type"] == "image/x-png") 
|| ($_FILES["file"]["type"] == "image/png")) 
|| ($_FILES["file"]["type"] == "video/mp4")) 
&& ($_FILES["file"]["size"] < 200000) 
&& in_array($extension, $allowedExts)) { 
    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("uploads/" . $_FILES["file"]["name"])) { 
     echo $_FILES["file"]["name"] . " already exists. "; 
    } else { 
     move_uploaded_file($_FILES["file"]["tmp_name"], 
     "uploads/" . $_FILES["file"]["name"]); 
     echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; 
    } 
    } 
} else { 
    echo "Invalid file"; 
} 
?> 
enter code here 
changed my code to this 


<?php 
    ini_set('display_startup_errors',1); 
    ini_set('display_errors',1); 
    error_reporting(-1); 
    //include authentication here/ Gmail is good solution for now 
    //check if it's not allowing any other extenstion other than MP4 
    $allowedExts = array("gif", "jpeg", "jpg", "png","mp4"); 
    $temp = explode(".", $_FILES["file"]["name"]); 
    print_r($_FILES["file"]["type"]); 
    $extension = end($temp); 
    if (($_FILES["file"]["size"] < 200000)) { 
     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("uploads/" . $_FILES["file"]["name"])) { 
      echo $_FILES["file"]["name"] . " already exists. "; 
     } else { 
      move_uploaded_file($_FILES["file"]["tmp_name"], 
      "uploads/" . $_FILES["file"]["name"]); 
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"]; 
     } 
     } 
    } else { 
     echo "Invalid file"; 
    } 
    ?> 

还是同样的错误

视频/ mp4Invalid文件

+1

你的'print_r($ _ FILES [“file”] [“type”])的输出是什么?并非每个浏览器都会为相同的文件发送相同的MIME类型。 –

+0

print_r($ _ FILES [“file”] [“type”])的输出是video/mp4。没有错误 – nickalchemist

回答

1

您必须修改POST最大尺寸,文件上传大小在php.ini

它应该是这样的,如果你想禁用限制:

; Maximum size of POST data that PHP will accept. 
; Its value may be 0 to disable the limit. It is ignored if POST data reading 
; is disabled through enable_post_data_reading. 
; http://php.net/post-max-size 
post_max_size=0 

,当然还有文件限制:

; Maximum allowed size for uploaded files. 
; http://php.net/upload-max-filesize 
upload_max_filesize=1000M