2013-02-22 81 views
0

好吧,我要建一些客戶一個基本的圖片上傳和我遇到某種錯誤的,我撕裂了我的頭髮。PHP Image Uploader - 截斷數組後處理?

後,我得到了$ _FILES數組我做了一點處理,使其更容易解析圖像,但後處理我的價值觀被截斷。

以下是有關PHP:

function organizeFilesArray(&$file_post) { 

    $file_array = array(); 
    $file_count = count($file_post['name']); 
    $file_keys = array_keys($file_post); 

    for ($i=0; $i<$file_count; $i++) { 
     foreach ($file_keys as $key) { 
      $file_array[$i][$key] = $file_post[$key][$i]; 
      echo "$file_array[$i][$key]"; 
      echo " ... "; 
      echo "$file_post[$key][$i] "; 
     } 
     echo "$file_count "; 

    } 

    return $file_array; 
} 

if(isset($_POST)){ 
    $destinationDirectory = '/Applications/MAMP/htdocs/image_upload/uploads/'; 

    //check if _FILES array is empty or if the file was uploaded via POST 
    if(!isset($_FILES['ImageFile']) || !is_uploaded_file($_FILES['ImageFile']['tmp_name'])){ 
     die('Something went wrong with Upload!'); 
    } 

    //clean up the array so I can handle it simply 
    //$imageArray = organizeFilesArray($_FILES['ImageFile']); 
    $file_array = organizeFilesArray($_FILES['ImageFile']); 
    echo" array size pp: " . sizeof($file_array); 
    foreach($file_array as $file){ 
     //random number to be added after image name 
     $randomNumber = rand(0, 9999999999); 

     //access these values by using their index position 
     //$imageName = str_replace(' ','-',strtolower($file['name'])); 
     $imageName = $file['name']; //get file name 
     $imageSize = $file['size']; // Obtain original image size 
     $tempSrc = $file['tmp_name']; // Tmp name of image file stored in PHP tmp folder 
     $imageType = $file['type']; //Obtain file type, returns "image/png", image/jpeg, text/plain etc. 

     echo "This is the type before we try: " . $file['type']; 
     echo "This is the name before we try: " . $file['name']; 
     echo "This is the size before we try: " . $file['size']; 
     //make sure filetype is supported 
     switch(strtolower($imageType)){ 
      case 'image/png': 
       $createdImage = imagecreatefrompng($file['tmp_name']); 
       break; 
      case 'image/gif': 
       $createdImage = imagecreatefromgif($file['tmp_name']); 
       break; 
      case 'image/jpeg': 
      case 'image/pjpeg': 
       $createdImage = imagecreatefromjpeg($file['tmp_name']); 
       break; 
      default: 
       die('Unsupported File!:'.$imageType); //output error and exit 
     } 

對不起,在那裏所有的print語句,試圖找出發生了什麼事情。當試圖上載的東西我得到這個(從螢火蟲): enter image description here

所以..處理後,一切都在我的數組被截斷爲它看起來像第一個字符?任何幫助將不勝感激!

回答

1

看起來你可能會分手只是你上傳的文件之一。

嘗試改變:

$file_array = organizeFilesArray($_FILES['ImageFile']); 

只是

$file_array = organizeFilesArray($_FILES); 
+1

事實旁邊,我最後不得不完全重新編寫的函數,哈哈,這是問題的一部分!謝謝! – dwf 2013-03-06 01:23:31