The best solution for CodeIgniter and SWFUpload integration _php Tutorials

Source: Internet
Author: User
Tags codeigniter
CodeIgniter is a lightweight, convenient MVC framework, the recent project involves batch upload, so, is to use the SWFUpload this plugin, although there are many on the internet on CI and swfupload posts, but, is not very complete, so, here comprehensive advantages of each home, After their own practical experience, did the next finishing.

Question 1: Can't get file type?

Answer: Because swfupload all types of file mime are application/octet-stream, so the use of CodeIgniter with the upload class can not be accurately obtained is a picture, according to the official CI wiki has been given a solution

In your view file, include the swfupload JavaScript file:

Copy the Code code as follows:
In your controller, pass "Filedata" as the name value for the Do_upload function:
$this->upload->do_upload (' Filedata ')
In your mimes.php file, add ' Application/octet-stream ' to all allowed image formats
' gif ' = = Array (' Image/gif ', ' Application/octet-stream '),
' jpeg ' = = Array (' Image/jpeg ', ' image/pjpeg ', ' Application/octet-stream '),
' jpg ' = = Array (' Image/jpeg ', ' image/pjpeg ', ' Application/octet-stream '),
' JPE ' = = Array (' Image/jpeg ', ' image/pjpeg ', ' Application/octet-stream '),
' png ' = = Array (' Image/png ', ' image/x-png ', ' Application/octet-stream '),

Issue 2: Background with session verification, will result in the status of exit after uploading

Reply:

General method: Swfuplaod in the upload, will be a new process, and the original process is inconsistent, to solve this problem, you need to specify session_id, and then on the login page to judge, if there is a post over the session_id, then use the function session_id ($_ post[' Php_sessionid ') to specify a bit.
Upload the page JS inside, you can get the current session_id.

Status in CI: In general, as Uploadify,swfupload uses flash clients, they produce useragent that are necessarily different from the user-agent of the user using the browser. So, while the user is logged into your system, a session is generated, but when the upload program is triggered another session is created (with the above useragent option turned on).

So, not the session is lost, but when you upload the file, CI for uploadify another session created.

Workaround 1: Set $config[' Sess_match_useragent '] to false and try again.

Workaround 2 ( recommended ): For security reasons, it is not recommended to use the 1th solution, but to use a different authentication method, such as at each upload, add a token to the server side of the token match (for example, the token can be a hash value of the user name). Please refer to the Stblog upload verification implementation (using SWFUpload) for the specific implementation method. ----I tried this method, the point is that if your session class is automatically loaded in AutoLoad, then this is definitely a failure, the workaround is to create a new class, such as My_controller inherited from Ci_controller, for background login , need permission to judge the background processing, say upload class inherits in Ci_controller such words, do not pass the session class of verification, of course upload still have to verify, but can use Post_params pass value to verify:

Example:
Copy the Code code as follows: Class Upload extends Ci_controller {
//*******
//*****
}
//~~~~~~~~~~~~~~~~~
Class Client_photo extends My_controller {
function __construct () {
Parent::__construct ();
}
function index () {
}
}
//~~~~~~~~~~~~~~~~~~~~~
Class My_controller extends Ci_controller {
Public Function __construct () {
Parent::__construct ();
$this->load->library (' Session ');
}
}

http://www.bkjia.com/PHPjc/788608.html www.bkjia.com true http://www.bkjia.com/PHPjc/788608.html techarticle CodeIgniter is a lightweight, convenient MVC framework, the recent project involves batch upload, so, is the use of swfupload this plug-in, although there are many on the internet on CI and swfupload posts ...

  • Related Article

    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.