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. Linux添加系统环境变量的两种方法

    方法一 export PATH=/usr/local/bin:$PATH 这种方法的PATH 在终端关闭 后就会消失.所以还是建议通过编辑/etc/profile来改PATH 方法二 # vim /e ...

  2. windows加固方案

    1     账号管理.认证授权.... 1 1.1      账号... 1 1.2      口令... 1 1.3      授权... 2 2     日志配置操作.... 3 3     IP ...

  3. (转)初识suse——linux

    Linux这种系统很奇怪,差不多每种不同的版本,它所使用的安装等一些重要命令皆有所变化.假若,你要熟练掌握一种OS,那么如果安装软件/应用,那是入门的第一步.   安装命令中: RedHat.Cent ...

  4. HTML之禁止输入文本

    一个文本框,禁止输入文本有2个方式,一个是利用readonly ,一个是利用 disabled. 那么两者虽然目的都可以达到,但是从表现上来看disabled会显得更加的直观,为什么这么说. 请看截图 ...

  5. thinkphp5.0 生命周期

    1.入口文件 // 应用入口文件 index.php // 定义项目路径 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 r ...

  6. POJ 2482 Stars in Your Window

    线段树+离散化+扫描线 AC之后,又认真读了一遍题目,好文章. #include<cstdio> #include<map> #include<algorithm> ...

  7. Protocol buffers--python 实践(一) 简介以及安装与使用

    由于最近对grpc产生了浓厚的兴趣,但是那是一整套东西,看了一下用到的东西不少,所以抽丝剥茧先写写这几天调研的protocol buffer -python的收获. 简介: 以下引用自官方首页文档: ...

  8. iOS关于UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的传递页面推送

    关于UITabView和UIAlertController,UIAlertAction以及UINavigation,值修改的传递 集合嵌套集合的操作 声明 两个必须的的代理 实现部分代码 - (voi ...

  9. HDU 2498 Digits

    水题.题目这样定义的,另f(x)为x有几位,x[i]=f(x[i-1]); 求最小的i使得x[i]==x[i-1] #include<cstdio> #include<cstring ...

  10. SecureCRT上传bash: rz: command not found

    SecureCRT上传bash: rz: command not found -bash: rz: command not found rz命令没找到? 执行sz,同样也没找到.     安装lrzs ...