Uploadify upload graph function based on thinkphp
PHP Action Server Side
/*
* 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 () {
Here to fix uploadify in Firefox under the HTTP 302 error reset session
$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 Upload file size
$upload->maxsize = 204800;
Set Upload file type
$upload->allowexts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ');
Set Attachments Upload Directory
$upload->thumb = true;
$upload->thumbprefix = ' m_ '; Production of 2 thumbnail pictures
Set thumbnail maximum width
$upload->thumbmaxwidth = ' 400,100 ';
Set thumbnail maximum height
$upload->thumbmaxheight = ' 400,100 ';
$upload->savepath = './uploads/shunongjj/';
Settings need to generate thumbnails, only valid for image files
Set the reference Picture Class Library package path
Delete Original
$upload->thumbremoveorigin = true;
if (! $upload->upload ()) {
Capturing upload Exceptions
$this->error ($upload->geterrormsg ());
$data [' status ']= ' 0 ';
$this->ajaxreturn ($data, ' json ');
} else {
Get file information for successful uploads
$info = $upload->getuploadfileinfo ();
$imgpath = '/uploads/shunongjj/'. $info [0][' Savename '];
$data [' picurl '] = $imgpath;
$data [' status ']= ' 100 ';
$this->ajaxreturn ($data, ' json ');
}
}
}
/*
* No thumbnail image
*/
Public Function upload_wsl () {
Import ("ORG.Net.UploadFile");
Import Upload Class
if ($_files) {
$upload = new UploadFile ();
Set Upload file size
$upload->maxsize = 204800;
Set Upload file type
$upload->allowexts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ');
Set Attachments Upload Directory
$upload->savepath = './uploads/shunongjj/';
Settings need to generate thumbnails, only valid for image files
Set the reference Picture Class Library package path
Delete Original
$upload->thumbremoveorigin = true;
if (! $upload->upload ()) {
Capturing upload Exceptions
$this->error ($upload->geterrormsg ());
$data [' status ']= ' 0 ';
return false;
$this->ajaxreturn ("", "Upload Failed", "");
} else {
Get file information for successful uploads
$info = $upload->getuploadfileinfo ();
return $imgpath = '/uploads/shunongjj/'. $info [0][' Savename '];
}
}
}
/*
* Company Rotation homepage Picture
*/
Public Function Upload_index () {
Import ("ORG.Net.UploadFile");
Import Upload Class
if ($_files) {
$upload = new UploadFile ();
Set Upload file size
$upload->maxsize = 204800;
Set Upload file type
$upload->allowexts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ');
Set Attachments Upload Directory
$upload->savepath = './uploads/shunongjj/';
Settings need to generate thumbnails, only valid for image files
Set the reference Picture Class Library package path
Delete Original
$upload->thumbremoveorigin = true;
if (! $upload->upload ()) {
Capturing upload Exceptions
$this->error ($upload->geterrormsg ());
$data [' status ']= ' 0 ';
$this->ajaxreturn ($data, ' json ');
} else {
Get file information for successful uploads
$info = $upload->getuploadfileinfo ();
$imgpath = '/uploads/shunongjj/'. $info [0][' Savename '];
$data [' picurl '] = $imgpath;
$data [' status ']= ' 100 ';
$this->ajaxreturn ($data, ' json ');
}
}
}
}
?>
Template TPL End
Html
(Image upload specification: 176*107)
Js
/**
* Uploadify plugin on the production of pictures
*/
$ ("#file_upload"). Uploadify ({
Specify SWF file
' swf ': ' __public__/uploadify/uploadify.swf ',
Pages processed in the background
' Uploader ': ' {: U ("Upload/upload")} ',
The text that the button displays
' ButtonText ': ' Upload image ',
Display height and width, default height 30;width 120
' Height ': 15,
' Width ': 80,
The type of upload file defaults to all files ' all '; '*.*'
Text displayed in the File Type drop-down menu at the bottom of the Browse window
' Filetypedesc ': ' Image Files ',
Allow file suffixes to be uploaded
' filetypeexts ': ' *.gif; *.jpg; *.png ',
Other parameters sent to the background are specified by Formdata
' FormData ': {' somekey ': ' somevalue ', ' Someotherkey ': 1},
Upload File page, the ID of the element you want to use as the file queue, default to False auto-generated, without #
' Queueid ': ' Filequeue ',
Automatically upload after selecting a file
' Auto ': true,
Set to True to allow multiple file uploads
' Onuploadsuccess ': function (file, data, response) {
var data = $.parsejson (data);
if (data.status==100) {
$ ("#img_show"). HTML ("");
$ ("#img_url"). Val (Data.picurl);
}else{
Alert ("Upload failed, may be the size of your uploaded image is not compliant, please try again!") ");
}
}
});
});