2016-11-30 93 views
0

我已經在PHP中創建了多個文件上傳功能。 當我嘗試上傳文件時,我一次選擇15個文件,處理請求時只有前四個文件存儲在數據庫中,並且每次都將15個文件上傳到目錄中。無法在php中上傳多個文件

我也檢查過PHP.ini文件,最大文件上傳限制爲50個預先請求,並且最大大小爲5M。仍然找到任何解決方案的問題。

爲什麼記錄僅保存爲前四個文件。

if($_POST['submit']== 'Upload_picture') 
    { 
     //echo "<pre>";  print_r($_FILES['upload_picture']['name']); 
     //die; 

     $album_title = $_GET['name']; 
     $album_id = $_GET['album']; 
     $album_dir = "../images/album/$album_title/"; #album path root directory 
     $db_album_dir = "images/album/$album_title/"; #batadase album path root directory 
     $error = array(); 
     $extension = array('jpg','gif','png','jpeg'); 
     foreach($_FILES['upload_picture']['tmp_name'] as $key => $tmp_name){ 
      $file_name = $_FILES['upload_picture']['name'][$key]; 
      $file_tmp = $_FILES['upload_picture']['tmp_name'][$key]; 
      $ext = pathinfo($file_name, PATHINFO_EXTENSION); 
      $new_filename = rand().".".$ext; #changing name 
      if(in_array($ext,$extension)) 
      { 
       if(move_uploaded_file($file_tmp= $_FILES['upload_picture']['tmp_name'][$key],"$album_dir$new_filename")) 
       { 
       # insert record database 

        $values = [ 
        'album_id' =>$album_id, 
        'image_name' => $new_filename, 
        'album_name' => $album_title, 
        'image_path' => $db_album_dir.$new_filename, 
        'uploaded_date' => date("Y/m/d h:i:s a") 
        ]; 
        include_once "action_page.php"; 
        $tablename = 'album_picture'; 
        $abc = new Demo(); 
        $res = $abc->insert($tablename,$values); 
        unset($abc); 
        $_SESSION['upload_success'] = "Files Uploaded succesfully"; 
        header("location:../upload_album.php?album=$album_id&name=$album_title"); 

       } 
       else 
       { 
         $_SESSION['upload_error'] = "Something went wrong, files cannot be uploaded"; 
       } 

      } 
      else 
      { 
       $_SESSION['upload_warning'] = "Please upload file"; 
       header("location:../upload_album.php?album=$album_id&name=$album_title"); 
      } 
     }//EOF FROEACH 
+0

首先檢查是否所有文件都通過打印有名字的foreach()循環 –

+0

裏面呀所有文件發佈成功與否根據請求發佈 –

回答

0

文件你輸入字段應該是這樣的:

<input type="file" id="file" name="name[]" multiple /> 

if(isset($_FILES['upload_picture']['name'])) 
    { 
     $file_name_all=""; 
     for($i=0; $i<count($_FILES['upload_picture']['name']); $i++) 
     { 
       $tmpFilePath = $_FILES['upload_picture']['tmp_name'][$i];  
       if ($tmpFilePath != "") 
       {  
        $path = "propertyimages/"; // create folder 
        $name = $_FILES['upload_picture']['name'][$i]; 
        $size = $_FILES['upload_picture']['size'][$i]; 

        list($txt, $ext) = explode(".", $name); 
        $file= time().substr(str_replace(" ", "_", $txt), 0); 
        $info = pathinfo($file); 
        $filename = $file.".".$ext; 
        if(move_uploaded_file($_FILES['upload_picture']['tmp_name'][$i], $path.$filename)) 
        { 
         $file_name_all.=$filename."*"; 
        } 
      } 
     } 
     $filepath = rtrim($file_name_all, '*'); 
     $tablename = 'album_picture'; 
     $abc = new Demo(); 
     $res = $abc->insert($tablename,$values); 
     unset($abc); 
     } 
     else 
    { 
     $filepath=""; 
    }