PhpAction server based on thinkphp's uploadify image upload function & lt ;? Php * & nbsp; * Tochangethistemplate, chooseTools | Templates & nbsp; * andopenthetemplateintheeditor. & nbsp; *** & nbsp; * Descript uploads graphs based on thinkphp's uploadify function
Php Action server
/*
* To change this template, choose Tools | Templates
* And open the template in the editor.
*/
/**
* Description of UploadAction
*
* @ Author hxwj
*/
Class UploadAction extends CommonAction {
Public function _ initialize (){
// Reset the SESSION to solve the http 302 error of Uploadify under Firefox.
$ Session_name = session_name ();
If (isset ($ _ POST [$ session_name]) {
Session_id ($ _ POST [$ session_name]);
Session_start ();
}
}
Public function upload (){
Import ("ORG. Net. UploadFile ");
// Import Upload class
If ($ _ FILES ){
$ Upload = new UploadFile ();
// Set the size of the uploaded file
$ Upload-> maxSize = 204800;
// Set the Upload file type
$ Upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'jpeg ');
// Set the attachment Upload Directory
$ Upload-> thumb = true;
$ Upload-> thumbPrefix ='m _ '; // produce two thumbnails.
// Set the maximum width of the thumbnail.
$ Upload-> thumbMaxWidth = '000000 ';
// Set the maximum height of the thumbnail.
$ Upload-> thumbMaxHeight = '000000 ';
$ Upload-> savePath = './Uploads/shunongjj /';
// Set the thumbnail to be generated, which is only valid for image files
// Set the path of the referenced image library package
// Delete the source image
// $ Upload-> thumbRemoveOrigin = true;
If (! $ Upload-> upload ()){
// Capture Upload exceptions
// $ This-> error ($ upload-> getErrorMsg ());
$ Data ['status'] = '0 ';
$ This-> ajaxReturn ($ data, 'json ');
} Else {
// Obtain the information of the successfully uploaded File
$ Info = $ upload-> getUploadFileInfo ();
$ Imgpath = '/Uploads/shunongjj/'. $ info [0] ['savename'];
$ Data ['picurl'] = $ imgpath;
$ Data ['status'] = '20140901 ';
$ This-> ajaxReturn ($ data, 'json ');
}
}
}
/*
* No thumbnail
*/
Public function upload_wsl (){
Import ("ORG. Net. UploadFile ");
// Import Upload class
If ($ _ FILES ){
$ Upload = new UploadFile ();
// Set the size of the uploaded file
$ Upload-> maxSize = 204800;
// Set the Upload file type
$ Upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'jpeg ');
// Set the attachment Upload Directory
$ Upload-> savePath = './Uploads/shunongjj /';
// Set the thumbnail to be generated, which is only valid for image files
// Set the path of the referenced image library package
// Delete the source image
// $ Upload-> thumbRemoveOrigin = true;
If (! $ Upload-> upload ()){
// Capture Upload exceptions
// $ This-> error ($ upload-> getErrorMsg ());
$ Data ['status'] = '0 ';
Return false;
// $ This-> ajaxReturn ("", "Upload failed ","");
} Else {
// Obtain the information of the successfully uploaded File
$ Info = $ upload-> getUploadFileInfo ();
Return $ imgpath = '/Uploads/shunongjj/'. $ info [0] ['savename'];
}
}
}
/*
* Company rotation homepage image
*/
Public function upload_index (){
Import ("ORG. Net. UploadFile ");
// Import Upload class
If ($ _ FILES ){
$ Upload = new UploadFile ();
// Set the size of the uploaded file
$ Upload-> maxSize = 204800;
// Set the Upload file type
$ Upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'jpeg ');
// Set the attachment Upload Directory
$ Upload-> savePath = './Uploads/shunongjj /';
// Set the thumbnail to be generated, which is only valid for image files
// Set the path of the referenced image library package
// Delete the source image
// $ Upload-> thumbRemoveOrigin = true;
If (! $ Upload-> upload ()){
// Capture Upload exceptions
// $ This-> error ($ upload-> getErrorMsg ());
$ Data ['status'] = '0 ';
$ This-> ajaxReturn ($ data, 'json ');
} Else {
// Obtain the information of the successfully uploaded File
$ Info = $ upload-> getUploadFileInfo ();
$ Imgpath = '/Uploads/shunongjj/'. $ info [0] ['savename'];
$ Data ['picurl'] = $ imgpath;
$ Data ['status'] = '20140901 ';
$ This-> ajaxReturn ($ data, 'json ');
}
}
}
}
?>
Template tpl end
Html
(Image Upload specification: 176*107)
Js