thinkPHP+Uploadify图片上传实例教程
首先,将下载的Uploadify压缩包解压放到公共文件夹内。实现代码如下:
1,前台html部分:
上传
2,action执行代码部分:
- public function uploadify()
- {
- $ph=M('Upload');
- import('ORG.Net.UploadFile');
- $upload = new UploadFile();// 实例化上传类
- $upload->maxSize = 93145728 ;// 设置附件上传大小
- $upload->saveRule =rand(1,9999);
- $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg','flv','avi','mov');// 设置附件上传类型
- $upload->savePath = './Uploads/';// 设置附件上传目录
- if(!$upload->upload())
- {// 上传错误提示错误信息
- $this->error($upload->getErrorMsg());
- }else{// 上传成功 获取上传文件信息
- $info = $upload->getUploadFileInfo();
- }
- for($i=0;$i {
- $data['name']=$info[$i]['savename'];
- $data['size']=$info[$i]['size'];
- $data['type']=$info[$i]['extension'];
- echo $info[$i]['savename'];
- $rs=$ph->add($data);
- }
- /*if($rs)
- {
- $this->success("成功");
- }else
- {
- $this->error("失败");
- }*/
- }
|