我正在使用以下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;
}
}
}
答案 0 :(得分: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/');
。
答案 1 :(得分: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;
}
}
}