jquery uploadify是一款Ajax风格的批量图片上传插件,在PHP中使用jquery uploadify很方便,请按照本文介绍的方法和步骤,为你的PHP程序增加jquery uploadify插件的批量上传图片功能。

本文是以dilicms为基础,为其增加图片上传功能。

1.增加数据表dili_fieldtypes新字段:k=>image,V=>图片上传区域(VACHAR);

2.修改application/libraries/dili/Field_behavior.php,在switch中增加如下代码:

case 'image':
$field=array(
'type'=>'VARCHAR',
'constraint'=>255,
'default'=>' '
);
break;

3. 修改 application/libraries/dili/Form.php 并且增加如下代码:

function _image($fileld,$default){
//$type= 'type=hidden';
//$width=($field['width'] ? $field['width'] : '570') .'px;';
//$height=($field['height'] ? $field['height'] : '415') .'px;';
return ;
}

4.在content_form.php和category_content_form.php中增加判断代码:

<?php
if($v['type']=="image"):
?>
<div id="fileQueue"></div>
<input type="file" id="uploadify" name="Filedata" />
<div>
<a href="javascript('#uploadify').uploadify('upload','*')">上传</a>
<a href="javascript('#uploadify').uploadify('cancel')">取消上传</a>
</div>
<input type="text" style="" name="<?php echo $v['name']?>" id="<?php echo $v['name']."_id"?>" value=""/>
<input type="hidden" style="" name="poster" id="<?php echo $v['name']."_id_1"?>" value=""/>
<link href="<?php echo $this->config->item("base_url");?>asset/js/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo $this->config->item("base_url");?>asset/js/uploadify/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#uploadify").uploadify({
'debug':false,
'swf': '<?php echo $this->config->item("base_url");?>asset/js/uploadify/uploadify.swf',
'uploader': '<?php echo $this->config->item("base_url");?>photo/savephoto',
'method':"post",
'height':30,
'width':120,
'queueID': 'fileQueue',
'auto': false,
'multi': false,
'fileTypeDesc':'只允许上传jpg格式图片',
'fileTypeExt':'*.jpg',
'fileSizeLimit' : '10MB',
'formData' : { '<?php echo session_name();?>' : '<?php echo $this->session->userdata('session_id');?>' },
'onUploadError' : function (file,errorCode,errorMsg,errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
},
'onUploadSuccess':function(file,data,response){
alert(data);
$("#<?php echo $v['name']."_id"?>").val(data);
$("#<?php echo $v['name']."_id_1"?>").val(data);
}
});
})
</script>
<?php endif;?>

6. 新建photo.php文件:

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
date_default_timezone_set('Asia/Shanghai');
class Photo extends Front_Controller{
public function __construct()
{
parent::__construct();
}
function _getFilePath()
{
$path="attachments/".date("Y")."/";
if(!file_exists($path)){
mkdir($path,'777');
}
$path.=date("m")."/";
if(!file_exists($path)){
mkdir($path,'777');
}
return $path;
}
function _creat_photothumbs($FileName,$setW){
$IMGInfo= getimagesize($FileName);
if(!$IMGInfo) return false;
if($IMGInfo['mime']== "image/pjpeg" || $IMGInfo['mime']=="image/jpeg"){
$ThisPhoto= imagecreatefromjpeg($FileName);
}elseif($IMGInfo['mime']== "image/x-png" || $IMGInfo['mime']== "image/png"){
$ThisPhoto= imagecreatefrompng($FileName);
}elseif($IMGInfo['mime']== "image/gif"){
$ThisPhoto=imagecreatefromgif($FileName);
}
$width=$IMGInfo['0'];
$height=$IMGInfo['1'];
$scale=$height/$width;
$nw=$setW;
$nh=$nw*$scale;
$NewPhoto=imagecreatetruecolor($nw,$nh);
imagecopyresampled($NewPhoto,$ThisPhoto,0,0,0,0,$nw,$nh,$width,$height);
ImageJpeg ($NewPhoto,$FileName);
return true;
}
function _savephoto_post(){
$dest_dir =$this->_getFilePath();
if (!empty($_FILES)) {
$date = date('Ymd');
//$dest_dir =$this->_getFilePath();
$photoname = $_FILES["Filedata"]['name'];
$phototype = $_FILES['Filedata']['type'];
$photosize = $_FILES['Filedata']['size'];
$fileInfo=pathinfo($photoname);
$extension=$fileInfo['extension'];
$newphotoname = date("YmdHis").mt_rand(10000,99999).'.'.$extension;
$dest=$dest_dir.$newphotoname;
//move_uploaded_file($_FILES['Filedata']['tmp_name'], iconv("UTF-8","gb2312",$dest));
move_uploaded_file($_FILES['Filedata']['tmp_name'], $dest);
//chmod($dest, 0755);
//如果宽度大于600则要进行裁剪
$arr=getimagesize($dest);
if($arr[0]>600){
$thumb_w=600;
$this->_creat_photothumbs($dest,$thumb_w);
}
//生成缩略图
$config2['image_library'] = 'gd2';
$config2['source_image'] = $dest;
$config2['create_thumb'] = TRUE;
$config2['maintain_ratio'] = TRUE;
$config2['width'] = 170;
$config2['height'] = 150;
$config2['master_dim']="width";
$config2['thumb_marker']="_1";
$this->load->library('image_lib', $config2);
$this->image_lib->resize();
echo $dest;
}
}
}
?>

好了,可以测试了。

在php中使用jquery uploadify进行多图片上传的更多相关文章

  1. jquery uploadify插件多文件上传

    1.jquery uploadify 下载:http://www.uploadify.com/ 2.安装:解压后拷贝的工程目录下面,如:WebRoot/uploaddify 3.配置项说明: uplo ...

  2. Uploadify & jQuery.imgAreaSelect 插件实现图片上传裁剪

    在网站中需要一个图片上传裁剪的功能,借鉴这篇文章 Ajax+PHP+jQuery图片截图上传 的指点,找到了jquery.imgAreaSelect这个不错插件,能对图片进行自定义区域选择并给出坐标, ...

  3. MVC4中基于bootstrap和HTML5的图片上传Jquery自定义控件

    场景:mvc4中上传图片,批量上传,上传前浏览,操作.图片进度条. 解决:自定义jquery控件 没有解决:非图片上传时,会有浏览样式的问题; 解决方案; 1.样式 – bootstrap 的css和 ...

  4. jQuery:[1]实现图片上传并预览

    jQuery:[1]实现图片上传并预览 原理 预览思路 1.当上传对象的input被触发并选择本地图片之后获取要上传的图片对象的URL: 2.把对象URL赋值给实现写好的img标签的src属性 Fil ...

  5. Silverlight中的拖拽实现的图片上传

    原文 http://blog.csdn.net/dujingjing1230/article/details/5443003 在Silverlight中因为可以直接从系统的文件夹里面拖出来一个文件直接 ...

  6. Android开发中使用七牛云存储进行图片上传下载

    Android开发中的图片存储本来就是比较耗时耗地的事情,而使用第三方的七牛云,便可以很好的解决这些后顾之忧,最近我也是在学习七牛的SDK,将使用过程在这记录下来,方便以后使用. 先说一下七牛云的存储 ...

  7. 使用jQuery Uploadify在ASP.NET 上传附件

    Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuer ...

  8. 基于jQuery仿uploadify的HTML5图片上传控件jquery.html5uploader

    (function($){ var methods = { init:function(options){ return this.each(function(){ var $this = $(thi ...

  9. jquery php ajax多图片上传.上传进度,生成缩略图

    本例用到其他2个php class.upload.php和 functions.php还有css和js以及img文件 下载地址为www.freejs.net/demo/91/down.zip 演示 J ...

随机推荐

  1. Delphi MaskEdit用法(转)

    源:http://www.cnblogs.com/zhangzhifeng/archive/2011/10/12/2208640.html MaskEdit是用来建立编辑框的,但它与Edit编辑框可以 ...

  2. regress_partition.sql

    --ENV --UAT @/test/change/env/env_test_uat.sql set echo on time on timing on set feedback on set pag ...

  3. 使用jquery模拟键盘事件,但window系统并不会真的响应事件,只是浏览器当前页面会响应而已

    <!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv= ...

  4. Hadoop远程调用机制

  5. tinkphp5.0 traits 的引入

    Traits引入 ThinkPHP 5.0开始采用trait功能(PHP5.4+)来作为一种扩展机制,可以方便的实现一个类库的多继承问题. trait是一种为类似 PHP 的单继承语言而准备的代码复用 ...

  6. HTML知识点

    1. 首页布局 // 顶部DIV#top{ position:absolute; top:; left:; width:100%; height:15%; overflow:hidden; margi ...

  7. Raspberry Pi 上使用WN725N连接WIFI

    系统版本 lee@Lee-RPi ~ $ uname -ar Linux Lee-RPi + # PREEMPT Thu Dec :: GMT armv6l GNU/Linux 这个版本的系统,已经集 ...

  8. Java中Calendar的用法

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Times } span.s1 { font: 13.0px Courier; backgro ...

  9. rsync+inotify实现数据的实时备份

    一.rsync概述 1.1.rsync的优点与不足 rsync与传统的cp.tar备份方式相比,rsync具有安全性高.备份迅速.支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需 ...

  10. PHP学习笔记-session

    session 在windows中的默认保存在AppDate/Local/Temp