php教程|php手册
yii,图片,上传,缩略图,生成
php教程-php手册
java md5 源码,ubuntu选择qt版本,tomcat启动未压缩项目,爬虫资源交易,php 无限参数函数,seo需要多长时间上百度首页lzw
这篇文章主要介绍了yii实现图片上传及缩略图生成的方法,详细分析了图片的上传及缩略图的生成原理与实现方法,是非常实用的技巧,需要的朋友可以参考下
新闻系统后台源码php,ubuntu系统批量注释,tomcat接口不规律阻塞,爬虫修改 url,php创建匿名函数,濮阳seo推广哪家公司做的好lzw
android购物车源码下载,ubuntu查看日记,tomcat内存最大是多少,soup 爬虫代码,php图片木马生成器,评论功能怎么做利于seolzw
本文实例讲述了利用yii框架来实现图片上传功能并在上传成功之后自动生成缩略图的方法,分享给大家供大家参考。具体实现方法如下:
Action文件:
复制代码 代码如下:
<?php
/**
* TestController.php
* Created on: -1-26 12:59:36 by Outsider
*/
class TestController extends CController {
/**
* 缩略图片生成
* @ path 图片路径
* @ width 图片宽度
* @ height 图片高度
*/
public function actionGetThumb($path, $w, $h) {
$file_name = md5($path . $w . $h);
if (file_exists(‘./temp/’ . $file_name . ‘.jpg’)) {
header(‘location:/temp/’ . $file_name . ‘.jpg’);
Yii::app()->end();
}
Yii::import(“ext.EPhpThumb.EPhpThumb”);
$thumb = new EPhpThumb();
$thumb->init();
$thumb->create(‘.’ . $path)
->adaptiveResize($w, $h)
->save(‘./temp/’ . $file_name . ‘.jpg’)
->show();
}
/*
* 图片显示
*/
public function actionList() {
$attache = Attache::model();
$list = $attache->findAll();
$this->render(‘list’, array(‘list’ => $list));
die;
}
/**
* 文件上传
*/
public function actionIndex() {
$path = getcwd() . ‘uploads’;
$dir = DIRECTORY_SEPARATOR . date(‘Y’) . DIRECTORY_SEPARATOR . date(‘m’);
$dir = str_replace(“\”, “/”, $dir);
$uploads_dir = str_replace(“\”, “/”, $path . $dir);
if (!is_dir($uploads_dir) || !is_writeable($uploads_dir)) {
mkdir($uploads_dir, 0777, TRUE);
touch($uploads_dir . ‘/index.html’);
}
$uploaded = false;
$model = new Upload();
if (isset($_POST[‘Upload’])) {
$model->attributes = $_POST[‘Upload’];
$file = CUploadedFile::getInstance($model, ‘file’);
$newName = substr(md5($file->extensionName . round((microtime(true) * 1000))), 0, 17) . ‘.’ . $file->extensionName;
$file_name = $uploads_dir . ‘/’ . $newName;
if ($model->validate()) {
$attache = new Attache();
$uploaded = $file->saveAs($file_name, TRUE);
$attache->name = $file->getName();
$attache->path = $dir . ‘/’ . $newName;
$attache->create_time = time();
$attache->save();
}
}
$this->render(‘index’, array(
‘model’ => $model,
‘uploaded’ => $uploaded,
‘dir’ => $uploads_dir,
));
}
}
Upload.php:
复制代码 代码如下: