Uploadify upload graph function based on thinkphp

Source: Internet
Author: User

PHP Action Server Side

<?php


/*
* 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 resolve Uploadify in Firefox under the HTTP 302 error once again set 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 Folder
$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 Folder
$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 Folder
$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

<input id= "File_upload" name= "file_upload" type= "file"/> (image Upload specification: 176*107)


Js

<script src= "__public__/uploadify/jquery.uploadify.min.js" type= "Text/javascript" ></script>
<link rel= "stylesheet" type= "Text/css" href= "__public__/uploadify/uploadify.css"/>

/**
* 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 the full file ' all files '; ‘*.*‘
Text displayed in the File Type drop-down menu at the bottom of the browse form
' Filetypedesc ': ' Image Files ',
Agree to upload the file suffix
' filetypeexts ': ' *.gif; *.jpg; *.png ',
Other references sent to the background are specified by Formdata
' FormData ': {' somekey ': ' somevalue ', ' Someotherkey ': 1},
Upload File page, you want to use as the file queue element ID, default feel false self-generated, without #
' Queueid ': ' Filequeue ',
Self-upload after selecting files
' Auto ': true,
Set to true to agree to 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!") ");
}
}
});
});


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.