Yii Uploadify batch upload and yiiuploadify batch upload

Source: Internet
Author: User

Yii Uploadify batch upload and yiiuploadify batch upload

Controller:

 

$ Reinfo = "fail ";
$ Filename = "";
// Important:
// When uploadify is used for upload, The sessionID changes each time,
// The negative effect after the change is that other session values under sessionID cannot be obtained. For example, the Yii: app ()-> session ['ik '] value changes.
// However, the value of this field cannot be changed. The Yii: app ()-> session ['ik '] value must be used for verification,
// Therefore, you must use this statement session_id ($ pse). It is used to change the sessionID back, which is consistent with the original sessionID to get the value smoothly.
// With this value, the original sessionID is consistent with the uploaded sessionID.
// Echo Yii: app ()-> session-> sessionID; this is the method for Yii to get sessionID
// W. one
$ Pse = Yii: app ()-> request-> getParam ('phpsession ');
Session_id ($ pse );
/*
* If you do not use the above sentence, Yii: app ()-> session ['ik '] = $ who cannot be equal because sessionID has changed
*/
$ Who = (int) Yii: app ()-> request-> getParam ('who ');
$ Sjm = Yii: app ()-> request-> getParam ('sjm ');
$ Zlsjm = Yii: app ()-> request-> getParam ("zlsjm ");
// $ Xceikey = (int) Yii: app ()-> request-> getParam ('xceikey'); // obtain the album ikey. Select by default, the value is null. You must select a value.
If ($ who = Yii: app ()-> session ['ik ']) {
$ Sjz = time ();
$ TempFile = $ _ FILES ['filedata'];
$ CheckType = pathinfo ($ tempFile ["name"], PATHINFO_EXTENSION );
If ($ checkType! = "Notimg "){
$ TargetPath = $ _ SERVER ['document _ root']. '/oa/upload/file /';
$ Scfile = date ("Y "). date ("m "). date ("d "). date ("His "). "_". $ who. "_". md5 (microtime ()). ". ". $ checkType;
$ TargetFile = str_replace ('//', '/', $ targetPath). $ scfile;
If (move_uploaded_file ($ tempFile ['tmp _ name'], $ targetFile )){
$ Relativeurl = "./upload/file/". $ scfile;
// $ Relativeurl = $ tempFile ["name"];
$ Zlfj = new Zlfj ();
$ Zlfj-> fj_zlsjm = $ zlsjm;
$ Zlfj-> fj_uikey = Yii: app ()-> session ["ik"];
$ Zlfj-> fj_path = "./upload/file/". $ scfile;
$ Zlfj-> fj_time = time ();
$ Zlfj-> fj_name = $ tempFile ["name"];
If ($ zlfj-> validate () & $ zlfj-> save ()){
$ Reinfo = $ relativeurl;
$ Filename = $ tempFile ["name"];
} Else {
@ Unlink ($ targetFile );
}

}
}
}
Echo CJSON: encode (array ("info" => "$ reinfo", "name" => $ filename ));

 

 

 

View:

 

<Script type = "text/javascript">
$ (Function (){
Ii = 0;
$ ('# Xceimgs2'). uploadify ({
'Formdata ':{
'Sjm': '<? Php echo md5 (time ();?> ',
'Who ': "<? Php echo Yii: app ()-> session ['ik '];?> ",
'Phpsession': '<? Php echo Yii: app ()-> session-> sessionID;?> ',
},
'Swf ':' <? Php echo JS;?> Uploadify.swf? Var = '+ (new Date (). getTime (),
'Upload': './index. php? R = site/uploadify1 ',
// Change the default select files to the Chinese 'select file'
'Buttontext': 'upload an attachment ',
// The width of the browser button
'Width': '123 ',
// View the height of the button
'Height': '26 ',
// Text displayed in the file type drop-down menu at the bottom of the browser window
'Filetypedesc': 'supported formats :',
// File suffix that can be uploaded
'Filetypeexts': '*. doc ',
// Size limit of uploaded files
'Filesizelimmit ': '50mb ',
// Upload quantity
'Queuesizelimit ': 50,
// Sets whether multiple files can be uploaded at a time.
'Multi ': true,

// Triggered when the user selects a file and click OK. Each file is triggered once.
'Onselect': function (file ){

},

'Onuploadstart': function (file ){
$ ("# Xceimgs2 "). uploadify ("settings", "formData", {'zlsjm': $ ("# juece_zlsjm "). val (), 'zlikey': $ ("# juece_zlikey "). val ()});
},

'Onuploadsuccess': function (file, data, response ){
Json = eval ("(" + data + ")");
// Alert (json ["name"]); return false;
// If the value is not equal to fail, the upload is successful.
If (json.info! = "Fail "){
$ ("# Jueceim" + ii). attr ("src", "<? Php echo IMG. "doc.jpg";?> ");
$ ("# Jueceb" + ii). text (json. name );
$ ("# Juecedele" + ii). attr ("src", "<? Php echo IMG. "delete2.png";?> ");
$ ("# Juecedele" + ii). attr ("value", json.info );
Ii ++;
}
},

// An error is returned, which is triggered when a file is selected.
'Onselecterror ': function (file, errorCode, errorMsg ){
Switch (errorCode ){
Cases-100:
Alert ("the number of uploaded files has exceeded the system limit of 50! ");
Break;
Cases-110:
Alert ("file [" + file. name + "] The size exceeds the system limit" + $ ('# xceimgs2 '). uploadify ('settings', 'filesizelimit ') + "size! ");
Break;
Cases-120:
Alert ("file [" + file. name + "] size exception! ");
Break;
Cases-130:
The alert ("file [" + file. name + "] type is incorrect! ");
Break;
Default:
}
}
});
});
</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.