yii完成图片上传及缩略图生成的方式_php实例_脚本之家

本文实例陈述了应用yii框架来达成图片上传功效并在上传成功现在自动生成缩略图的秘技,共享给大家供大家参谋。具体贯彻情势如下:

Action文件:复制代码 代码如下:create
->adaptiveResize ->save(‘./temp/’ . $file_name . ‘.jpg’)
->show(); } /* * 图片展现 */ public function actionList() {
$attache = Attache::model(); $list = $attache->findAll();
$this->render(‘list’, array; die; } /** * 文件上传 */ public
function actionIndex . ‘uploads’; $dir = DIRECTORY_SEPARATOR . date .
DIRECTORY_SEPARATOR . date; $dir = str_replace; $uploads_dir =
str_replace(“”, “/”, $path . $dir); if || !is_writeable {
mkdir($uploads_dir, 0777, TRUE); touch($uploads_dir . ‘/index.html’);
} $uploaded = false; $model = new Upload(); if (isset {
$model->attributes = $_POST[‘Upload’]; $file =
CUploadedFile::getInstance; $newName =
substr(md5($file->extensionName . round * 1000))), 0, 17) . ‘.’ .
$file->extensionName; $file_name = $uploads_dir . ‘/’ . $newName;
if { $attache = new Attache(); $uploaded = $file->saveAs;
$attache->name = $file->getName(); $attache->path = $dir . ‘/’
. $newName; $attache->create_time = time; } }
$this->render(‘index’, array( ‘model’ => $model, ‘uploaded’ =>
$uploaded, ‘dir’ => $uploads_dir, )); }}

Upload.php:复制代码 代码如下: ‘jpg,
gif, png,zip’卡塔尔(英语:State of Qatar), 卡塔尔(قطر‎; }}图表突显页面:

自定义图片大小,缩略图自动生成复制代码
代码如下:
图片 1-%3EcreateUrl(‘test/getThumb’,%20array(‘path’%20=%3E%20’/uploads’%20.%20$v%5B’path’%5D,%20’w’%20=%3E%20’150′,%20’h’%20=%3E%20’150’))%20?%3E)

图表上传表单:复制代码 代码如下:

File was uploaded. Check .

‘multipart/form-data’))?>

希望本文所述对大家基于Yii框架的PHP程序设计有所支持。

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website