2016-05-18 262 views
0

我正在使用下面的php腳本來上傳圖片。如何使用php class.upload.php上傳2個大小的多個圖像?

https://github.com/verot/class.upload.php/blob/master/README.md

好了,現在我要上傳多張圖片,2種尺寸。一個是和其他是

因此,要得到這樣的結果,我使用下面的代碼,但它不保存此圖像 - >$handle->file_new_name_body = 'mpic_thumb'.uniqid('', true);

PHP代碼:

foreach ($files as $file) { 

    $handle = new upload($file); 

    if ($handle->uploaded) { 

     $handle->file_new_name_body = 'mpic_'.uniqid('', true); 
     $handle->image_resize   = true; 
     $handle->image_ratio_fill  = true; 
     $handle->image_x    = 360; 
     $handle->image_y    = 240;     


     $handle->file_new_name_body = 'mpic_thumb'.uniqid('', true); 
     $handle->image_resize   = true; 
     $handle->image_ratio_fill  = true; 
     $handle->image_x    = 100; 
     $handle->image_y    = 65; 

     $handle->process('images/menu_images/'); 
     if ($handle->processed) { 
      echo 'image thumb resized'; 
      $handle->clean(); 
     } else { 
      echo 'error : ' . $handle->error; 
     } 
    } 
} 
+0

哦,它現在正在工作。我必須調用'$ handle-> process('images/menu_images /');'在第一個屬性:)後 –

+0

而不是這樣做,嘗試創建2個單獨的函數,一個用於縮略圖,另一個用於普通圖像。此外可能有一個問題,圖像的尺寸小於這個尺寸 – Nehal

+0

是的正是這正是我想說的@ shibbir ahmed – Nehal

回答

0

你需要做他們seperately 。您正在有效覆蓋設置。嘗試這樣的事情

foreach ($files as $file) { 

$handle = new upload($file); 

if ($handle->uploaded) { 

    $handle->file_new_name_body = 'mpic_'.uniqid('', true); 
    $handle->image_resize   = true; 
    $handle->image_ratio_fill  = true; 
    $handle->image_x    = 360; 
    $handle->image_y    = 240;     
    $handle->process('images/menu_images/'); 
    if ($handle->processed) { 
     echo 'image thumb resized'; 
     $handle->clean(); 
    } else { 
     echo 'error : ' . $handle->error; 
    } 

    $handle->file_new_name_body = 'mpic_thumb'.uniqid('', true); 
    $handle->image_resize   = true; 
    $handle->image_ratio_fill  = true; 
    $handle->image_x    = 100; 
    $handle->image_y    = 65; 

    $handle->process('images/menu_images/'); 
    if ($handle->processed) { 
     echo 'image thumb resized'; 
     $handle->clean(); 
    } else { 
     echo 'error : ' . $handle->error; 
    } 
} 
} 
1

使用單獨的兩個功能就是這樣,並分別對其進行處理:

foreach ($files as $file) { 

    $handle = new upload($file); 

    if ($handle->uploaded) { 

    $handle->file_new_name_body = 'mpic_'.uniqid('', true); 
    $handle->image_resize   = true; 
    $handle->image_ratio_fill  = true; 
    $handle->image_x    = 360; 
    $handle->image_y    = 240;     
    $handle->process('images/menu_images/'); 
    if ($handle->processed) { 
     echo 'image thumb resized'; 
     $handle->clean(); 
    } else { 
     echo 'error : ' . $handle->error; 
    } 

    $handle->file_new_name_body = 'mpic_thumb'.uniqid('', true); 
    $handle->image_resize   = true; 
    $handle->image_ratio_fill  = true; 
    $handle->image_x    = 100; 
    $handle->image_y    = 65; 

    $handle->process('images/menu_images/'); 
    if ($handle->processed) { 
     echo 'image thumb resized'; 
     $handle->clean(); 
    } else { 
     echo 'error : ' . $handle->error; 
    } 
    } 
} 

另外,另一種方法是兩個圖像功能之後調用$handle->process('images/menu_images/');