Ext.apply(this,{
items: [form_set_field,form_set_file],
buttons: [btnOK,btnCancel],
});
uploadPhotoWindow.superclass.initComponent.call(this);
},
savePhoto:function (){
//alert(this.cur_sele_po_no);
var form_set_field=this.getComponent('form_set_field');
var form_set_file=this.getComponent('form_set_file');
form_set_field.getForm().submit({
waitMsg : '上传成功,正在存储 saveing....',waitTitle:'请稍候 waiting....',
url:'php/jsonfile/po_nophotolist_json.php',
method : 'post',
success : function(form, action){
var out = action.result.success;
if (out != true){
Ext.Msg.alert('提示 Tips ', '存储失败,错误信息Save failure:'+action.result.msg);
} else{
Ext.Msg.alert('提示 Tips ', '存储成功,服务器信息: Save success '+action.result.msg);
form_set_file.getForm().reset();
form_set_file.ownerCt.haveUpload=true;
}
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
break;
}
},
});
},
isUpload:function(){
return this.haveUpload;
}
});
后台php photoUpload.php'
?
require_once('../classfile/guid.class.php');
if(!isset($_FILES['imgFile'])){
echo json_encode(array("success"=false, 'msg'="Not get Imgfile"));
return;
}
$upfile=$_FILES['imgFile'];
$name=$upfile["name"];//上传文件的文件名
$type=$upfile["type"];//上传文件的类型
$size=$upfile["size"];//上传文件的大小
$tmp_name=$upfile["tmp_name"];//上传文件的临时存放路径
$error_cod=$upfile["error"];
if ($error_cod0){
echo json_encode(array("success"=false, 'msg'=$error_cod));
}
$ext_file_name="";
switch ($type){
case 'image/pjpeg':
$okType=true;
$ext_file_name =".jpg";
break;
case 'image/jpeg':
$okType=true;
$ext_file_name =".jpg";
break;
case 'image/gif':
$okType=true;
$ext_file_name =".gif";
break;
case 'image/png':
$okType=true;
$ext_file_name =".png";
break;
}
if(!$okType){
echo json_encode(array("success"=false, 'msg'="Notimage "));
return;
}
$web_root="D:".DIRECTORY_SEPARATOR."Easy2PHP5".DIRECTORY_SEPARATOR."webSiteJfz".DIRECTORY_SEPARATOR;
$photo_tmp_path=$web_root."img".DIRECTORY_SEPARATOR."userimg".DIRECTORY_SEPARATOR."temp";
$temp_file_name= creat_guid(0).$ext_file_name;
$photo_tmp_file_name=$photo_tmp_path.DIRECTORY_SEPARATOR.$temp_file_name;
$photo_tmp_file_scr="img".DIRECTORY_SEPARATOR."userimg".DIRECTORY_SEPARATOR."temp".DIRECTORY_SEPARATOR.$temp_file_name;
move_uploaded_file($tmp_name,$photo_tmp_file_name);
echo json_encode(array("success"=true, 'msg'= "ok","file_name"=$photo_tmp_file_name,"file_scr"=$photo_tmp_file_scr));
//echo json_encode(array("success"=false, 'msg'= json_encode($_FILES['imgFile'])));
return;
?
guid.class.php // 生成唯一的图片文件名
?
function creat_guid($long){
$uuid="";
if (function_exists('com_create_guid')){
$uuid=com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
推荐阅读
- 手机电脑怎么跨屏互联显示,手机电脑怎么跨屏操作
- 包含jquery如何判断复选框是否选中的词条
- 棋牌即时策略游戏,棋牌即刻
- 区块链是基石吗,区块链是基石吗知乎
- linux命令重启系统 重启命令 linux
- 直播会员收入是什么收入,主播会员
- 投屏声音怎么调到电视机,投屏声音怎么投到电视上
- 花椒直播和虎牙有什么关系,虎牙和花椒主播收入哪个高
- phpcsv大量数据 php 读取csv文件