2016-05-18 11 views
0

私は次のPHPスクリプトを使用して画像をアップロードしています。php class.upload.phpを使用して2つのサイズの画像を複数アップロードするには?

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

まあ、今は2つのサイズで複数の画像をアップロードしたいです。 1つはが大きく、があり、その他はが小さいです。だから、

、この結果を得るために、私は次のコードを使用していますが、それはこの小さなイメージ - >$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

ああ、それは今動作しています。この方法ではなく、最初のプロパティ: –

+0

の後に '$ handle-> process( 'images/menu_images /');を呼び出す必要があります。別の関数を2つ作成しようとすると、1つはサムネイル用、もう1つは通常画像用です。また画像のサイズがそのサイズよりも小さいという問題があるかもしれません – Nehal

+0

はい、私が言うようにしようとしていたものでした@shibbir ahmed – Nehal

答えて

0

あなたが個別にそれらを行う必要があるが。効果的に設定を上書きしています。このように、両方の機能別にこの

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/');です。

関連する問題