_php instance of the best solution for integrating CodeIgniter with SWFUpload

Source: Internet
Author: User
Tags codeigniter

CodeIgniter is a lightweight, convenient MVC framework, the recent project involved in bulk upload, so, is the use of swfupload this plug-in, although there are a lot of CI and swfupload posts, but not very complete, so, here to synthesize the advantages of each family, After their own practical experience, do the next finishing.

Question 1: Cannot get file type?

Answer: Because swfupload all types of files mime is application/octet-stream, so the use of CodeIgniter upload class can not accurately obtain whether the image, according to CI official wiki has been given a solution

In your view file, include the swfupload JavaScript file:

Copy Code code as follows:
<script type= "Text/javascript" src= "Jscripts/swfupload/mmswfupload.js" ></script>
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 '),

Problem 2: The background with session verification will result in the status of landing after uploading

Reply:

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

Status in CI: Generally, because Uploadify,swfupload uses flash clients, they produce useragent that are necessarily different from the user-agent that users use browsers. So, while the user logs on to your system, a session is generated, but when the upload program is triggered it will produce another one (with the above useragent option turned on).

So, not session lost, but when you upload files, ci for Uploadify created another session.

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 instead to use a different authentication method, such as in each upload, in the URL to append a token to the server side of the token (such as this token can be the user name of the hash value). The concrete implementation method please refer to the Stblog upload verification implementation (uses is SWFUpload). ----I tried this method, and the point is, if your session class is automatically loaded in AutoLoad, then this is definitely a failure, and the solution is to create a new class, such as My_controller inherited from Ci_controller, for background logging. , need the right to judge background processing, said upload class inherited from ci_controller such words, not through the session class verification, of course, upload still have to verify, but you can use the Post_params value for verification:

Example:

Copy 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 ');
}
}

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.