2012-04-25 10 views
0

私は1つのアップロードと複数のアップロードを持っています。 1つのアップロードは、サイズが6MBのファイルで試してみると動作します。PHPマルチファイルのアップロード

6MBファイルでマルチファイルアップロードを試してみてください。

アイデア?

$messages = array(); 
$errors = array(); 

$upload_dir = '.'; 
if(isset($_FILES['file']['tmp_name'])){ 
    //Number of uploaded files. 
    $num_files = count($_FILES['file']['tmp_name']); 

    //loop over array of files 
    for($i=0; $i<$num_files; $i++){ 

     //check if there is a file in the array. 
     if(!is_uploaded_file($_FILES['file']['tmp_name'][$i])){ 
      //echo $_FILES['file']['tmp_name'][$i].': Upload Failed!'; 

     }else{ 
      //echo $_FILES['file']['tmp_name'][$i].': Upload good!'; 
      //lets insert the data into the DB. 
      $filename = stripslashes($_FILES['file']['name'][$i]); 
      $extension = getExtension($filename); 
      $description = $_POST['description'][$i]; 

      if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
      { 
       //print error message 
       $error[$i] = $filename.': '.'Unknown file extension! '; 

      } 
      else 
      { 
       //get the size of the image in bytes 
       //$_FILES['image']['tmp_name'] is the temporary filename of the file 
       //in which the uploaded file was stored on the server 
       $size=filesize($_FILES['file']['tmp_name'][$i]); 


       //compare the size with the maxim size we defined and print error if bigger 
       if ($size > MAX_SIZE*1024) 
       { 
        //echo '<h1>You have exceeded the size limit of 100MB!</h1>'; 
        $errors[$i]=$filename.': You have exceeded the size limit of 100MB'; 
       } 

       //we will give an unique name, for example the time in unix time format 
       $time = time()+$i; 
       $image_name=$time.'.'.$extension; 

       //the new name will be containing the full path where will be stored (images folder) 
       $newname='D:\\uploads\\'.$image_name; 
       //$newname=$image_name; 
       //we verify if the image has been uploaded, and print error instead 
       $copied = copy($_FILES['file']['tmp_name'][$i], $newname); 
       if (!$copied) 
       { 
        $messages[$i]= $filename.': '.'Copy unsuccessful!'; 
        //echo 'Copy unsuccessful!'; 

       }else{ 
        $messages[$i]= $filename.': '.'Copy successful!'; 
        //get image information here. 
        $fileInfo = getimagesize($newname); 
        $mySize = $fileInfo[0]; 
        $mimetype = image_type_to_mime_type($fileInfo[2]); 
        $dimensions = $fileInfo[3]; 
        savePhotoInfo($image_name,$dimensions, $description,$mySize); 
        createThumb('D:\\uploads\\', 'D:\\uploads\\thumbnails\\', '180',$image_name); 
        //echo 'Copy successful!'; 
       } 
      } 
     } 
    } 

    echo 'Upload results:'; 
    echo '<br />'; 

    for($x=0;$x<count($messages);$x++){ 
     echo $messages[$x]; 
     echo '<br />'; 
    } 

    echo 'Upload errors:'; 
    echo '<br />'; 
    for($x=0;$x<count($errors);$x++){ 
     echo $errors[$x]; 
     echo '<br />'; 
    } 

} 
+0

"それは機能しません"とはどういう意味ですか?エラーはありますか? –

+0

意味、エラーなし、ファイルサイズが大きすぎない、何もありません。それだけで実行し、停止/完了します。ファイルはアップロードされません。 –

答えて

0

あなたは、php.ini、アップロードサイズの設定を見てください:私は、そのような時間を設定してみましたか?

+0

はい、私は最大サイズを10MBに設定しました:upload_max_filesize = 10M –

+0

元のポスターの質問を聞いて、コメントには適していますが、それ自身の答えは適切ではありません。 – Wiseguy

関連する問題