Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Integration of codeigniter and swfupload

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to realize the integration of codeigniter and swfupload". In the daily operation, I believe many people have doubts about how to realize the integration of codeigniter and swfupload. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to realize the integration of codeigniter and swfupload"! Next, please follow the editor to study!

Question1: can't get the file type?

Answer: since the MIME of all types of files in SWFUPLOAD is application/octet-stream, it is impossible to accurately obtain whether it is a picture by using the upload class that comes with Codeigniter. According to the official wiki of ci, the answer has been given.

In your view file, include the SWFUpload javascript file:

The copy code is 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' for 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')

Question 2: backend with session verification will result in exit login after upload

Answer:

General method: when swfuplaod uploads, it will start a new process, which is inconsistent with the original process. To solve this problem, you need to specify session_id, and then judge on the login page. If there is a session_id from post, specify it with the function session_id ($_ POST ['PHP_SESSIONID']).

In the JS of the upload page, you can get the current SESSION_ID.

State in ci: in general, because uploadify,swfupload uses flash clients, the useragent generated by them must be different from the user-agent that the user uses the browser. So, although the user logs in to your system and generates a session, another session is generated when the upload program is triggered (with the useragent option turned on above).

So, it's not that session is lost, but when you upload the file, CI creates another session for uploadify.

Solution 1: set $config ['sess_match_useragent'] to FALSE and try again.

Solution 2 (recommended): for security reasons, it is not recommended to use the first solution, but to use another verification method, such as attaching a token to the server-side token comparison in the url each time you upload (for example, this token can be the hash value of the user name). For more information on how to implement it, please see the upload verification implementation of stblog (using swfupload). -I tried this method, and the point is, if your session class is loaded automatically in autoload, then it must be a failure. The solution is to create a new class, for example, MY_Controller inherits from CI_Controller and is used for background login, which requires permission judgment background processing. If you say that the upload class inherits from CI_Controller, it will not be verified by the session class. Of course, the upload still has to be verified. However, you can use post_params to pass a value for verification:

Example:

The copy code is 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')

}

}

At this point, the study on "how to achieve the integration of codeigniter and swfupload" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report