浏览器怎么预览php文件上传,PHP不使用flash来实现文件上传,兼容各种浏览器

直接上代码

前端代码:

上传照片

  • 添加图片

匿名

/*global window, $ */

$(function () {

'use strict';

// Change this to the location of your server-side upload handler:

//var url = "{{ upload_url }}?resourceType=comment_image&resourceId=1";

var url = '/commentUpload';

$('#fileupload').fileupload({

url: url,

dataType: 'json',

// imageMaxWidth:600,

//imageMaxHeight:350,

add: function(e, data) {

var uploadErrors = [];

var acceptFileTypes = /^image\/(gif|jpe?g|png)$/i;

if(data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {

uploadErrors.push('请选择图片格式上传');

}

if( data.originalFiles[0]['size'] > 5000000) {

uploadErrors.push('你选择的文件大小超过上传限制');

}

if(uploadErrors.length > 0) {

alert(uploadErrors.join("\n"));

} else {

data.submit();

}

},

done: function (e, data) {

console.log(data.result);

if(parseInt(data.result.error) == 0){

if($("#pic_container li").size() 

$("#pic_container").append(

'

'

                                +''

+''

+'

'

                                +''

+'

'

+'

'

);

}else{

alert("你选择的文件数量超过上传限制");

return false;

}

}

}

}).prop('disabled', !$.support.fileInput)

.parent().addClass($.support.fileInput ? undefined : 'disabled');

});

后台代码:

$post = array();

$post['resourceType'] ='comment_image';

$post['resourceId'] = 1 ;

$post['getImageInfo'] = 'true' ;

$post['comment_image_file'] = '@'.$_FILES['comment_image_file']['tmp_name'].';filename='.$_FILES['comment_image_file']['name'].';type='.$_FILES['comment_image_file']['type'];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,CONFIG::get('api.loupanCommentImageUpload'));

curl_setopt($ch, CURLOPT_POST,true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

curl_exec ($ch);

curl_close ($ch);

使用Curl的方式上传文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值