我可以用phpthumb上传图片和调整大小,但我怎么也能上传原始图片呢?
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
// upload the image
if ($form->station_image->isUploaded()) {
$form->station_image->receive();
$station_image = '/upload/images/radio/' . basename($form->station_image->getFileName());
//upload thumb
include_once '../library/PhpThumb/ThumbLib.inc.php';
$thumb = PhpThumbFactory::create($form->station_image->getFileName());
$thumb->resize(50, 50)->save($form->station_image->getFileName());
//thumb ends
}else{
echo 'cannot upload'. exit;
}我的表单如下所示
$station_image->setLabel('Upload File: ')
->setDestination(APPLICATION_PATH.'/../public/upload/images/radio')
->addValidator('Extension', false, 'jpg,png,gif')
->addValidator('Size', false, 902400)
->addValidator('Count', false, 1)
->setRequired(false);请告诉我如何上传多个缩略图,或者我如何让原始文件也上传?谢谢
发布于 2012-04-18 11:00:09
您正在将原始图像传递给PHPThumb的构造函数:
$thumb = PhpThumbFactory::create($form->station_image->getFileName());所以$form->station_image->getFileName()是你的原始文件。问题是您正在用调整大小的文件名覆盖原始文件名,请尝试以下操作:
$thumb = PhpThumbFactory::create($form->station_image->getFileName());
$thumb->resize(50, 50)->save('/path/where/you/want/resized/image/to/go.png');-更新--
试一试:
if ($form->station_image->isUploaded()) {
$form->station_image->receive();
$station_image = '/upload/images/radio/' . basename($form->station_image->getFileName());
//upload thumb
include_once '../library/PhpThumb/ThumbLib.inc.php';
$thumb = PhpThumbFactory::create($form->station_image->getFileName());
// Notice this is using $station_image, which I assume is an accessible path
// by your webserver
$thumb->resize(50, 50)->save($station_image);
//thumb ends
}else{-更新--
尝试更改此设置:
$station_image = '/upload/images/radio/' . basename($form->station_image->getFileName());要这样做:
$station_image = '/upload/images/radio/thumb_' . basename($form->station_image->getFileName());https://stackoverflow.com/questions/10202172
复制相似问题