2012-01-19 3 views
1

나는 내 이미지 업로드 코드에서 다음과 같은 오류 얻을 :경고 : getimagesize (배열) [function.getimagesize] : 스트림을 열지 못했습니다 :

$submit = $_POST['submit']; 
if(isset($submit)){ // check if user has submitted a the form 
if(isset($_FILES['files'])){ // check if a file has been submitted in the form 
    foreach($_FILES['files']['tmp_name'] as $key => $tmp_name){ // Loop through each Image if more than one image has been uploaded 

     // Get image info 
     $temp_dir = $_FILES['files']['tmp_name']; // Temporary location of file 
     $image_type = $_FILES['files']['type']; // Image filetype 
     $image_size = $_FILES['files']['size']; // Image file size 
     $image_name = $_FILES['files']['name']; // Image file name 

     // Get image width and height 
     $image_dimensions = getimagesize($temp_dir); // returns an array of image info [0] = width, [1] = height 
     $image_width = $image_dimensions[0]; // Image width 
     $image_height = $image_dimensions[1]; // Image height 

     // Get form info 
     $category = $_POST['cat']; 
     $create_album = $_POST['album']; 
     $select_album = $_POST['choose_album']; 

     if($_FILES['files']['error'][$key] = UPLOAD_ERR_OK){ // Check to make sure there are no errors in the file (0) 
      //$filetype = ($type == 'image/jpeg') ? '.jpeg': str_replace('image/','',$type); 

      // Make sure each filename name is unique when it is uploaded 
      $random_name = rand(1000,9999).rand(1000,9999).rand(1000,9999).rand(1000,9999); 

      // Set the path to where the full size image will be stored 
      $path = 'img/'.$random_name . $_FILES['files']['name'][$key]; 

      // Set the path to where the thumb image will be stored 
      $thumb_path = 'img/thumb_/'.$random_name .$_FILES['files']['name'][$key]; 

      // Set the Maximum dimensions the images are allowed to be 
      $max_width = 4040; 
      $max_height = 4040; 

      // Set the Maximum file size allowed (5MB) 
      $max_size = 5242880; 

      // Set the file extensions that are allowed to be uploaded and store them in an array 
      $allowed = array('image/jpeg','image/png','image/gif'); 

      if(in_array($image_type,$allowed)){ // Check to make sure the image that is being uploaded has a file extension that we permit 
       if(($img_width < $max_width) && ($img_height < $max_height)){ // Check to make sure the Image dimensions do not exceed the maximum dimensions allowed 
        if($image_size < $max_size){ // Check to make sure the Image filesize does not exceed the maximum filesize allowed 
         $input_album = (!empty($create_album)) ? $create_album: $select_album;// Check to make sure the user has created an album or has select an existing album 
         // Check the shape of the Image (square, standing rectangle, lying rectangle) and assign a value depening on which it is 
         $case = image_shape($image_width, $image_height); 
         echo $case; 
        }else{ 
         echo '<p>Error uploading '. $image_name .': Image filesize exceeds permitted filesize ('. $max_size .')</p>'; 
        } 
       }else{ 
        echo '<p>Error uploading '. $image_name .': Image dimensions exceed permitted dimensions ('.$max_width.' x '. $max_height .')</p>'; 
       } 

      } 

     }else{ 
     echo '<p>Cannot upload image, file error: '. $_FILES['files'][$key].'</p>'; 
     } 
    } // End of foreach 

}else{ 
    echo '<p>Cannot upload image, no image selected for uploading.</p>'; 
} 
: 여기

Warning: getimagesize(Array) [function.getimagesize]: failed to open stream: No such file or directory in H:\Programs\webserver\root\media\images\upload.php on line 41 

지금까지 코드

} 여기

$_FILES

Array ([files] => Array ([name] => Array ([0] => fyros_09.jpg) [type] => Array ([0] => image/jpeg) [tmp_name] => Array ([0] => C:\Users\chris-vaio\AppData\Local\Temp\php7754.tmp) [error] => Array ([0] => 0) [size] => Array ([0] => 122773))) 
print_r 인 691,363,210
+0

해결 방법은 없지만 오류 검사가 올바르지 않으면'if ($ _ FILES [ 'files'] [ 'error'] [$ key]를 사용하여 주어진 경로 (getimagesize() 매개 변수)를 확인하십시오. – Cyclonecode

답변

1

당신이 다중 파일 PHP 배열 이름 설정을 사용하고 나타납니다

<input type="file" name="file[]"> 
<input type="file" name="file[]"> 

$temp_dir = $_FILES['files']['tmp_name']; // Temporary location of file 
$image_type = $_FILES['files']['type']; // Image filetype 
$image_size = $_FILES['files']['size']; // Image file size 
$image_name = $_FILES['files']['name']; // Image file name 

이 잘못된 것을 의미한다. 사용 하시려는 분

$temp_dir = $_FILES['files'][$key]['tmp_name']; 
          ^^^^^^--- missing this part. 
$image_type = etc.... 

isset($_FILES)을 사용하지 마십시오. 그것은 신뢰할 수 없습니다. 각 파일의 개별 하위 배열에 ['error'] 속성을 사용하여 업로드 실패/성공을 위해 확인해야합니다

foreach($_FILES['files']['tmp_name'] as $key => $tmp_name) { 
    if ($_FILES['files'][$key]['error'] !== UPLOAD_ERR_OK) { 
     die("File #$key failed with error code " . $_FILES['files'][$key]['error']); 
    } 
    etc... 
} 
+0

Marc, 내가 가지고 있었던 두 번째 쟁점을 해결했고, 잘 설명했다! " – crm

0

// Get image info 
$temp_dir = $_FILES['files'][$key]['tmp_name']; // Temporary location of file 
$image_type = $_FILES['files'][$key]['type']; // Image filetype 
$image_size = $_FILES['files'][$key]['size']; // Image file size 
$image_name = $_FILES['files'][$key]['name']; // Image file name 

PS의 : getimagesize()을 파일을 찾을 수 없습니다.

관련 문제