图片上传骨架
sql
-- phpMyAdmin SQL Dump -- version phpStudy 2014 -- http://www.phpmyadmin.net -- -- 主机: localhost -- 生成日期: 2014 年 12 月 04 日 16:11 -- 服务器版本: 5.5.38 -- PHP 版本: 5.3.28 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- 数据库: `imgf` -- -- -------------------------------------------------------- -- -- 表的结构 `xp_photo` -- CREATE TABLE IF NOT EXISTS `xp_photo` ( `id` int(11) NOT NULL AUTO_INCREMENT, `image` varchar(200) COLLATE utf8_bin NOT NULL, `create_time` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=24 ; -- -- 转存表中的数据 `xp_photo` -- INSERT INTO `xp_photo` (`id`, `image`, `create_time`) VALUES (1, ‘54800a0a03d09.png‘, 1417677321), (2, ‘54800a2716e36.png‘, 1417677351), (3, ‘54800a9ac28cb.png‘, 1417677466), (4, ‘54800aa790f56.png‘, 1417677479), (5, ‘54800af698968.png‘, 1417677558), (6, ‘54800b015f5e1.png‘, 1417677569), (7, ‘54800d895b8d8.png‘, 1417678217), (8, ‘54800e882dc6c.png‘, 1417678472), (9, ‘54800f79c28cb.png‘, 1417678713), (10, ‘54800fa840d99.png‘, 1417678760), (11, ‘548010db0f424.png‘, 1417679067), (12, ‘548010fcaba95.png‘, 1417679100), (13, ‘548011198d24d.png‘, 1417679129), (14, ‘5480113444aa2.png‘, 1417679156), (15, ‘548011a2501bd.png‘, 1417679266), (16, ‘548012299c671.png‘, 1417679401), (17, ‘548012623d090.png‘, 1417679458), (18, ‘548012775f5e1.png‘, 1417679479), (19, ‘548012bfd59f8.png‘, 1417679551), (20, ‘548012ff2625a.png‘, 1417679615), (21, ‘54801386c28cb.png‘, 1417679750), (22, ‘54801591ca2dd.png‘, 1417680273), (23, ‘5480168c29f63.png‘, 1417680524); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
config
<?php return array( //‘配置项‘=>‘配置值‘ //‘USERNAME‘=>‘admin‘, //赋值 //数据库配置信息 ‘DB_TYPE‘ => ‘mysql‘, // 数据库类型 ‘DB_HOST‘ => ‘localhost‘, // 服务器地址 ‘DB_NAME‘ => ‘imgf‘, // 数据库名 ‘DB_USER‘ => ‘root‘, // 用户名 ‘DB_PWD‘ => ‘root‘, // 密码 ‘DB_PORT‘ => 3306, // 端口 ‘DB_PREFIX‘ => ‘xp_‘, // 数据库表前缀 //其他项目配置参数 // ... ); ?>
显示页
可能是版本关系,标签无法显示缩略图 <notempty name="data"><img src="__UPLOAD__/m_{$data.image}" /> <img src="__UPLOAD__/s_{$data.image}" /></notempty> <form id="upload" method=‘post‘ action="__URL__/upload/" enctype="multipart/form-data"> <input name="image" id="image" type="file" /> <input type="submit" value="提交" class="button" > </form>
控制器
<?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { public function index(){ $this->display(); } public function upload() { if (!empty($_FILES)) { //如果有文件上传 上传附件 $this->_upload(); } } // 文件上传 protected function _upload() { import(‘ORG.Net.UploadFile‘); //导入上传类 $upload = new UploadFile(); //设置上传文件大小 $upload->maxSize = 3292200; //设置上传文件类型 $upload->allowExts = explode(‘,‘, ‘jpg,gif,png,jpeg‘); //设置附件上传目录 $upload->savePath = ‘./Uploads/‘; //设置需要生成缩略图,仅对图像文件有效 $upload->thumb = true; $upload->imageClassPath = ‘ORG.Util.Image‘;// 设置引用图片类库包路径、缩略图 //设置需要生成缩略图的文件后缀 $upload->thumbPrefix = ‘m_,s_‘; //生产2张缩略图,s是小缩略图,m也是小缩略图 //设置缩略图最大宽度 $upload->thumbMaxWidth = ‘400,100‘; //设置缩略图最大高度 $upload->thumbMaxHeight = ‘400,100‘; //设置上传文件规则 $upload->saveRule = ‘uniqid‘; //删除原图 $upload->thumbRemoveOrigin = true; if (!$upload->upload()) { //捕获上传异常 $this->error($upload->getErrorMsg()); } else { //取得成功上传的文件信息 $uploadList = $upload->getUploadFileInfo(); import(‘ORG.Util.Image‘);// 设置引用图片类库包路径、水印 //给m_缩略图添加水印, Image::water(‘原文件名‘,‘水印图片地址‘) Image::water($uploadList[0][‘savepath‘] . ‘m_‘ . $uploadList[0][‘savename‘], APP_PATH.‘Tpl/tpl/logo.png‘); $_POST[‘image‘] = $uploadList[0][‘savename‘]; } $model = M(‘Photo‘); //保存当前数据对象 $data[‘image‘] = $_POST[‘image‘]; $data[‘create_time‘] = NOW_TIME; $list = $model->add($data); if ($list !== false) { $this->success(‘上传图片成功!‘); } else { $this->error(‘上传图片失败!‘); } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。