Dedecms5.7 realize batch upload picture two times development

Source: Internet
Author: User

Implementation steps:
1. Download 5.6, go to the official download 5.6 version, pay attention to the code to be consistent!
Under Include folder, copy the FCKeditor folder to the Include folder in 5.7!
2. Modify the background configuration: as shown in the picture, change to FCK

CKEditor Image Bulk upload (zend+php)
1: Requirements
A request in the project, the original background of the merchandise picture can only one upload, now requires optimization for one can upload more than once, and directly into the editor
2: Thinking
Still use the original upload pictures of the program, just upload the page to add multiple upload input box, submit, all files are submitted to the background controller, modify the controller processing code and callback functions
3: Steps
(1) New pictures Bulk Upload tab tags
1.1 Fckeditor/editor/lang/zh-cn.js File New tab variable declaration
Dlgmultiupload: "Upload pictures in bulk",

1.2 fckeditor/editor/dialog/fck_image/fck_image.js file Add tab tag call

The code is as follows Copy Code




if (fckconfig.imageupload)


Dialog. AddTab (' Multiupload ', fcklang.dlgmultiupload);





if (Tabcode = = "Multiupload")//this tab tab page also has an album category to get


{


Dialog. Sizer.resizedialog (450,450);//Initialize the size of the pop-up box


$.getjson ('/picture/cate/get ', {},function (data) {//In other projects this is not necessary


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 File New pictures bulk upload URL


Fckconfig.imagemultiuploadurl = '/picture/upload/multisave ';


(2) Page layout settings


Fckeditor/editor/dialog/fck_image.html





<div id= "Divmultiupload" style= "Display:none" >


<form id= "Frmmultiupload" method= "Post target=" UploadWindow1 "enctype=" Multipart/form-data "action=" "onsubmit=" return Checkmultiupload (); " >


<input id= "TxtUploadFile1" style= "width:80%" type= "file" size= "a" name= "Multiphotofile0_f"/><br/>< br/>


<input id= "TxtUploadFile2" style= "width:80%" type= "file" size= "a" name= "Multiphotofile1_f"/><br/>< br/>


<input id= "TxtUploadFile3" style= "width:80%" type= "file" size= "a" name= "Multiphotofile2_f"/><br/>< br/>


<input id= "txtUploadFile4" style= "width:80%" type= "file" size= "a" name= "Multiphotofile3_f"/><br/>< br/>


<input id= "TxtUploadFile5" style= "width:80%" type= "file" size= "a" name= "Multiphotofile4_f"/><br/>< br/>


<input id= "TxtUploadFile6" style= "width:80%" type= "file" size= "a" name= "Multiphotofile5_f"/><br/>< br/>


<div>


<label style= ' line-height:20px; ' ><span style= ' line-height:20px; ' > Compression: </span><input type= ' checkbox ' name= ' multi_compress ' value= ' 1 ' checked= ' checked '


<label style= ' line-height:20px; ' ><span style= ' line-height:20px; ' > Add watermark: </span><input type= ' checkbox ' name= ' multi_water ' value= ' 1 ' checked= ' checked ' <br/>


Album: <select id= "multi_albumlist" style= ' display:none ' name= ' multi_cate_id ' ></select>


<a href= ' javascript:void (0) ' id= ' Multi_linkcreatealbum "onclick=" return Multi_checkalbum (); "> new album </a>


<input type= "text" id= "Multi_newalbuminput" name= "Multi_album_name" size= "ten" maxlength= "style= ' Display:none"; >


<button id= "Multi_btncreatealbum" style= ' display:none; ' onclick= ' return multi_createnewalbum (); "> Create </ button> <a href= "javascript:void (0)" id= "Multi_btncancelalbum" style= ' display:none; ' onclick= ' multi_ Cancelalbum () "> Cancel </a>


<input type= ' hidden ' name= ' multi_pic_f ' value= ' Goods_add '


</div>


<p><input id= "BtnUpload1" type= "submit" value= "Insert Picture"/></p>


<script type= "Text/javascript" >


document.write (' <iframe name= "UploadWindow1" style= "Display:none" src= "' + fcktools.getvoidurl () + '" ></ Iframe> ');


</script>


</form>


</div>


(3) JS Verification when submitting


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 &&am P Sfile5.length = = 0 && sfile6.length = 0)


{


Alert (' Please upload at least one picture ');


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) Callback function


function Callback_multisubmit (status, errid,html) {


if (status==0)


{


Insert a picture directly into the editor


var oparenteditor=window.parent.innerdialogloaded (). FCK;


oparenteditor.inserthtml (HTML);


Dialog. Closedialog ();


Return


}


Switch (Errid)


{


Case 0:


Alert (' This picture has not been uploaded successfully, please upload it again. ');


Break


Case 1:


Alert (' This photo was not uploaded successfully, album space is not sufficient. ');


Break


Case 2:


Alert (' This photo you selected is over 2MB, please choose again. ');


Break


Case 3:


Alert (' Picture is not well-formed, you can upload photos in jpg, GIF, and PNG format. ');


Break


Default:alert (' This picture has not been uploaded successfully, please upload it again. ');


}


}


(5) After submitting the controller processing

$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 _n AME] ["size"], $_files [$file _name] ["type"]);


$check _res = $file->check ();


if ($check _res!== true)


{


Error


if ($check _res = = 1)


{


echo "<script>parent.callback_multisubmit (1,2);</script>";


}


ElseIf ($check _res = 2)


{


echo "<script>parent.callback_multisubmit (1,3);</script>";


}


Return


}


$img _info = $file->upsend (); Return upload file information


if ($img _info = = False)


{


Error


echo "<script>parent.callback_submit (1,0);</script>";


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";


}


If the product is uploaded, all processed into JPG


if ($pic _f = = "Goods_add")


{


$filetype = "JPG";


}


/**


* Call picture Upload


*/


$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"])


{


/**


* Image upload Successful


*/


@unlink ($img _info ["Picturetruepath"]);


if ($pic _f = = "Goods_add")//Product upload


{


$img _url[$i] = $res ["RSP"] [img] ["Picture_path"]. '.' . $res ["RSP"] ["IMG"] ["File_type"];


$img _title[$i] = $title;





}


Else


{


echo "<script>parent.callback_multisubmit (0,0);</script>";


}


}


Else


{


echo "<script>parent.callback_multisubmit (1,0);</script>";


}


}


}


for ($i =0; $i <= $count; $i + +)


{


if (!empty ($img _url[$i]))


{


$callback _temp = "<img src= ' $img _url[$i] ' alt= ' $img _title[$i] '/><br/> ';


$callback _html. = $callback _temp;


}


}


Echo ' <script>parent.callback_multisubmit (0,0, "'. $callback _html. ' ");</script> ';


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.