我可以上传图片并使用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;
}
Run Code Online (Sandbox Code Playgroud)
我的表格看起来像这样
$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);
Run Code Online (Sandbox Code Playgroud)
请帮我如何上传多个缩略图或如何上传原始文件?谢谢
您正在将原始图像传递给PHPThumb的构造函数:
$thumb = PhpThumbFactory::create($form->station_image->getFileName());
Run Code Online (Sandbox Code Playgroud)
$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');
Run Code Online (Sandbox Code Playgroud)
- 更新 -
尝试一下:
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{
Run Code Online (Sandbox Code Playgroud)
- 更新 -
尝试改变这个:
$station_image = '/upload/images/radio/' . basename($form->station_image->getFileName());
Run Code Online (Sandbox Code Playgroud)
对此:
$station_image = '/upload/images/radio/thumb_' . basename($form->station_image->getFileName());
Run Code Online (Sandbox Code Playgroud)