2012-06-17 59 views
0

我正在嘗試使用一個簡單的腳本,它可以讓我將不同類型的媒體上傳到Web服務器,其中包括當前的視頻和照片格式。我遇到的問題是當我嘗試上傳視頻時,頁面上的表單似乎無法提交。在我單擊提交按鈕,頁面掛起片刻,然後返回到形式顯示,如果沒有提交。PHP Video Upload Form Time Out

我試圖增加$ max_file_size中的fileszie並且這沒有任何作用,它似乎沒有達到這個地方的用處。

我也在互聯網上搜索過,它建議我使用我的代碼頂部列出的「ini_set」特性來排除任何PHP表單提交問題 - 這些似乎沒有效果。

<?php 
ini_set('upload_max_filesize', '45M'); 
ini_set('post_max_size', '45M'); 
ini_set('max_input_time', 30000); 
ini_set('memory_limit', '45M'); 

$file_types_array=array("avi", "JPG", "jpeg", "flv", "mpeg", "FLV"); 
// File Size maximum set in bytes 
$max_file_size=35645847; 
// Test directory created on the server to allow for uploads 
// potential to direct to user spercific areas for secuirty concerns 
$upload_dir="uploads\\"; 
// Holds Unix Time in seconds, used for a unique stamp per upload to 
// avoud multiple images/videos having the same ID 
$stamp = time(); 
// Unique User ID - 123 for testing 
$UserID = 123; 
/* If the form is not submitted, display the form */ 
if(!isset($_POST["submitted"])){ 
    $form = "<form action='' method='post' enctype='multipart/form-data'>Upload files:<br /><input type='hidden' name='submitted' value='TRUE' id='".time()."'><input type='hidden' name='MAX_FILE_SIZE' value='".$max_file_size."'>"; 
     $form .= "<input type='file' name='file[]'><br />"; 
    $form .= "<input type='submit' value='Upload'><br />Valid file type(s): "; 
    // Displays the valid file types set in $file_types_array 
     for($x=0;$x<count($file_types_array);$x++){ 
      if($x<count($file_types_array)-1){ 
       $form .= $file_types_array[$x].", "; 
      }else{ 
       $form .= $file_types_array[$x]."."; 
      } 
     } 
    $form .= "</form>"; 
    echo($form); 
}else{ 
    foreach($_FILES["file"]["error"] as $key => $value){ 
     if($_FILES["file"]["name"][$key]!=""){ 
      if($value==UPLOAD_ERR_OK){ 
       $fileID = $_FILES["file"]["name"][$key]; 
       $filename = explode(".", $_FILES["file"]["name"][$key]); 
       $filenameext = $filename[count($filename)-1]; 

    // Checks for file extension   
    $file_ext_allow = FALSE; 
    for($x=0;$x<count($file_types_array);$x++){ 
     if($filenameext==$file_types_array[$x]){ 
      $file_ext_allow = TRUE; 
     } 
    } 
    if($file_ext_allow){ 
     if($_FILES["file"]["size"][$key]<$max_file_size){ 
     $fileWrite = $UserID."_".$stamp.".".$filenameext; 
      if(move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$fileWrite)){ 
       echo("File uploaded successfully.<br />"); 
      }else{ // Catch for unprepared error 
       echo($fileID." was not successfully uploaded<br />"); 
      } 
      }else{ // Catch for File Size too big 
       echo($fileID." was too big, not uploaded<br />"); 
      } 
      }else{ // Catch for bad File Name 
       echo($fileID." had an invalid file extension, not uploaded<br />"); 
      } 
      }else{ // Successful Output 
       echo($fileID." was not successfully uploaded<br />"); 
      } 
     } 
    } 
} 
?> 

有關這個主題的任何幫助將不勝感激,因爲我一直在一點點時間太長了這一段代碼盯着....

問候,

+0

只是要清楚:你能夠上傳圖像?那麼小視頻呢? –

回答

0

我不會」 t使用PHP上傳大文件,我會考慮使用類似this或使用HTML5上傳大文件。您只能使用簡單的舊式表單上傳,而最終用戶不知道發生了什麼。