2015-02-08 94 views
0

我试图上传一个mp4文件,虽然它不会经过。只要我输入格式,我就可以上传任何图像类型,但任何视频格式都是不可行的。 MP4,MOV等 这是我使用上传MP4使用PHP错误上传mp4文件

<?php 

    session_start(); 

if(!isset($_SESSION["user"]) or !is_array($_SESSION["user"]) or empty($_SESSION["user"])) { 
     // redirect to login page 
} 



$target_dir = ('../MEDIA/films/'); 
$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 


// Check if file already exists 

// Check file size 

// Allow certain file formats 
if($imageFileType != "MP4") { 
    echo "Sorry, only MP4, MOV, M4V, MKV & AVI files are allowed."; 
    $uploadOk = 0; 
} 
// Check if $uploadOk is set to 0 by an error 
if ($uploadOk == 0) { 
    echo "Sorry, your file was not uploaded."; 
// if everything is ok, try to upload file 
} else { 
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
    echo header('Location: main.php'); 
    } else { 
    echo header('Location: main.php'); 
    } 
} 
?> 

的代码和我的表单代码:

<div class="container auth"> 
 
    <div id="big-form" class="well auth-box"> 
 
    <form class="form-horizontal" action="video-upload.php" method="post" enctype="multipart/form-data"> 
 
     <fieldset> 
 

 
      <!-- Form Name --> 
 
      <legend>Uploading as <?= $_SESSION["user"]["firstname"] ?></legend> 
 

 
      <!-- Textarea --> 
 
       <div class="form-group"> 
 
      <div class="">    
 
    <input type="file" name="fileToUpload" id="fileToUpload"> 
 
      </div> 
 
      </div> 
 
<div class="form-group"> 
 
    <div class="col-md-8"> 
 
    <button id="updateprofile" value="Upload Video" name="updateprofile" class="btn btn-success">Submit</button> 
 
    </div> 
 
</div> 
 
     </fieldset> 
 
     </form> 
 
    </div> 
 
    <div class="clearfix"></div> 
 
    </div> 
 
</html>

+0

更具体吗?你有错误吗? – Mihai 2015-02-08 18:39:08

+0

对不起,是的。 我试过print_r,我得到了“Array()” 而这是错误: 注意:未定义索引:fileToUpload $ target_file = $ target_dir。基名($ _ FILES [ “fileToUpload”] [ “名称”]); – SARUAV 2015-02-08 18:41:21

+0

检查文件大小的一种方法'$ size = filesize($ _ FILES ['fileToUpload'] ['tmp_name']); if($ size> MAX_SIZE * 1024)..' – Mihai 2015-02-08 18:51:25

回答

1

也许您的视频文件太大了。如果可能,请检查upload_max_filesizepost_max_sizephp.ini

+1

啊发现它,使用phpinfo和最大上传大小为20mb xD – SARUAV 2015-02-08 18:50:03