我正在使用以下php脚本上传图像。
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;
}
}
}
像这样分别使用这两个函数,并分别处理它们:
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/');
。
您需要分别执行它们。您实际上正在覆盖设置。试试这个
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;
}
}
}