如何自动调整上传到此 foder 的图像大小:'assets/media/':
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Uploader_Controller extends Controller_Core {
public function bulkUpload() {
Kohana::log('debug', 'Start to upload');
$files = Validation::factory($_FILES)
->add_rules('picture', 'upload::valid', 'upload::required', 'upload::type[gif,jpg,png,jpeg]', 'upload::size[10M]');
Kohana::log('debug', 'Start to validate');
if ($files->validate()) {
Kohana::log('debug', 'validate passed');
$filename = upload::save('picture');
$thumbSize = Kohana::config('upload.thumb_size');
Image::factory($filename)
->resize($thumbSize[0], $thumbSize[1], Image::WIDTH)
->save(DOCROOT . 'assets/media/thumbs/' . basename($filename));
$partName = explode('/', $filename);
$picture = $partName[count($partName) - 1];
$data['name'] = '';
$data['picture'] = $picture;
$data['category_id'] = $this->input->post('category_id', 0);
$data['description'] = '';
;
$data['user_id'] = $this->input->post('user_id', 0);
$pictureModel = new Picture_Model();
try {
$photo = $pictureModel->savePicture($data);
echo url::site('assets/media/' . $picture);
} catch (Exception $e) {
}
}
}
}
我已经添加了这一行但仍然无法正常工作:
$filename->resizeToWidth(300);