if ( FCKConfig.ImageUpload )
dialog.AddTab( 'MultiUpload', FCKLang.DlgMultiUpload ) ;
if(tabCode =="MultiUpload")//此tab标签页面还有一个相册分类需要获取
{
dialog.Sizer.ResizeDialog(450,450);//初始化弹出框的大小
$.getJSON('/picture/cate/get',{},function(data){//在其他项目中这个不是必须的
if(data.items.length>0)
{
$("#multi_albumlist").empty();
$.each(data.items,function(i,cate){
var option = new Option(cate.cate_name,cate.cate_id);
$("#multi_albumlist").append(option);
});
}
else
{
var option = new Option('','');
$("#multi_albumlist").append(option);
}
$("#multi_albumlist").show();
});
}
1.3 fckeditor/fckconfig.js 文件新增图片批量上传Url
FCKConfig.ImageMultiUploadURL ='/picture/upload/multisave';
(2) 页面布局设置
fckeditor/editor/dialog/fck_image.html
(3) 提交时js验证
function CheckMultiUpload()
{
var sFile1 = GetE('txtUploadFile1').value ;
var sFile2 = GetE('txtUploadFile2').value ;
var sFile3 = GetE('txtUploadFile3').value ;
var sFile4 = GetE('txtUploadFile4').value ;
var sFile5 = GetE('txtUploadFile5').value ;
var sFile6 = GetE('txtUploadFile6').value ;
if ( sFile1.length == 0 && sFile2.length == 0 && sFile3.length == 0 && sFile6.length == 0 && sFile5.length == 0 && sFile6.length == 0)
{
alert( '请至少上传一张图片' ) ;
return false ;
}
if ( ( FCKConfig.ImageUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
( FCKConfig.ImageUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
{
OnUploadCompleted( 202 ) ;
return false ;
}
// Show animation
window.parent.Throbber.Show() ;
GetE( 'divMultiUpload' ).style.display = 'none' ;
return true ;
}
(4)回调函数
function callback_multisubmit(status, errid,html){
if(status==0)
{
//将图片直接插入到编辑器中
var oParentEditor=window.parent.InnerDialogLoaded().FCK;
oParentEditor.InsertHtml(html);
dialog.CloseDialog();
return;
}
switch(errid)
{
case 0 :
alert('该图片未上传成功,请重新上传。');
break;
case 1 :
alert('该照片未上传成功,相册空间不足。');
break;
case 2 :
alert('您选择的这张照片超过2MB,请重新选择。');
break;
case 3:
alert('图片格式不正确,您可以上传JPG、GIF和PNG格式的照片。');
break;
default : alert('该图片未上传成功,请重新上传。');
}
}
(5)提交后控制器处理
$img_url = array();
$img_title = array();
for($i=0;$i<$count;$i++)
{
$file_name = "MultiPhotoFile".$i."_f";
if(!empty($_FILES [$file_name]["tmp_name"]))
{
$file = new Henu_UploadFile ( '/temp/', $_FILES [$file_name] ["tmp_name"], $_FILES [$file_name] ["name"], $_FILES [$file_name] ["size"], $_FILES [$file_name] ["type"] );
$check_res = $file->check ();
if ($check_res !== true)
{
//报错
if ($check_res == 1)
{
echo "";
}
elseif ($check_res == 2)
{
echo "";
}
return;
}
$img_info = $file->upSend (); //返回上传文件信息
if ($img_info === false)
{
//报错
echo "";
return;
}
$title = $img_info ["OldName"];
$filetype = $img_info ["filetype"];
switch ($filetype)
{
case "image/jpg" :
$filetype = "jpg";
break;
case "image/gif" :
$filetype = "gif";
break;
case "image/png" :
$filetype = "png";
break;
default :
$filetype = "jpg";
}
//如果是商品上传,都处理成jpg
if ($pic_f == "goods_add")
{
$filetype = "jpg";
}
/**
* 调用图片上传
*/
$client->setConfig ( "upload", "index", "POST", array ("store_id" => $store_id, "cate_id" => $cate_id, "file_type" => $filetype, "title" => htmlspecialchars ( $title ), "water" => $water, "compress" => $compress, "ip" => ip2long ( real_ip () ) ), "picture" );
$http = $client->getHttp ();
$http->setFileUpload ( $img_info ["pictureTruePath"], 'img' );
$res = $client->getData ();
if (isset ( $res ["rsp"] ["img"] ))
{
/**
* 图片上传成功
*/
@unlink ( $img_info ["pictureTruePath"] );
if ($pic_f == "goods_add") //商品上传
{
https://img.111cn.net$img_url[$i] = $res ["rsp"] ["img"] ["picture_path"] . '.' . $res ["rsp"] ["img"] ["file_type"];
$img_title[$i] = $title;
}
else
{
echo "";
}
}
else
{
echo "";
}
}
}
for($i=0;$i<=$count;$i++)
{
if(!empty(https://img.111cn.net$img_url[$i]))
{
$callback_temp = " ";
$callback_html .= $callback_temp;
}
}
echo '';
}
|