Solve the thinkphp using upload plugin uploadify browser Firefox 302 error method _php tips

Source: Internet
Author: User
Tags sessions

Recently used thinkphp to develop a project, integrated the bulk upload file plug-in uploadify, Google Chrome and IE under the normal upload, only Firefox prompted this error, the Internet to find a lot of solutions, Basically said Flash in Firefox under the launch session, due to no validation of the sessions through so the error, the problem on the internet there are many solutions, but tried a lot, did not really solve my problem, finally saw the official solution
http://www.uploadify.com/documentation/uploadify/using-sessions-with-uploadify/
To really solve, I used the thinkphp framework, and I opened the _initialize () (Do not know the function to see the thinkphp Help manual), in this function, I executed a check whether the user log on the validation function, so that each access controller, will be executed to verify that the user has permission to perform the appropriate operation, but because in Firefox, Flash launched the request and not with SessionID sent to the thinkphp controller, so caused by the user login request, In this case, we can define a SessionID in the Formdata parameter of uploadify, so that we can send $_get to the controller through $_post or SessionID method. The controller sets the passing past SessionID to the current session's SessionID, so that it can be validated, but here's a note that the reset SessionID must be placed at the front of the execution verification login function, which is not valid, because if login verification does not pass, Then the code will not be executed, I have made such a mistake before, will reset the session to the upload file processing function, the following paste detailed code for your reference:

Client (thinkphp upload file template) code

$ (function ()
 {

   $ (' #file_upload '). Uploadify ({'

    formData ' 

: {

     ' <{:session_name ()}> ')

: ' <{:session_id ()}> ',
//Here get SessionID

     ' timestamp '

: ' <{$timestamp}> ',

     ' token ' 

: ' <{$token}> '

    }

     The following for solving this problem irrelevant code omitted ...

    })

}

Server-side (thinkphp Controller) code

Initialize execute public

function 
_initialize () {

  //here to resolve uploadify HTTP
 302 error reset session in Firefox

  $session _name

= Session_name ();

  If

(isset ($_post[$session _name]))
 {

   session_id ($_post[$session _name]);

   Session_Start ();

  }

   Perform login verification function

  $this->powerverify ();  

 }

For everyone to share my own personal examples, but also found some other friends on the Internet to organize the example, I hope to learn some inspiration.

Title: PHP uploadify Firefox report 302 error
probably reason: in uploadify official website already explained, is said that Flash has a bug it submits the request does not automatically bring the session, therefore the browser judgment did not obtain the session value, I use the thinkphp frame, _ Initialize () {} (this function is executed before executing other methods, I use it to determine whether the user is logged in), in this function, I follow the online method:
basic idea: according to the principle of flash this bug, we will be the session value as a parameter upload.
Uploadify Official website also said the solution: to give an option
FormData: {' Session NAME ': ' Sessioin ID '}----------------JSON format
I use hidden fields to keep these variables in the template (values can be obtained), and then I write directly in the JS file:

var session_name = (using jquery to get the value via selector)
var session_id = (IBID.);
FormData: {session_name, session_id},

Other ways to solve the problem:
This problem does exist, in fact, this problem can be translated into session loss. Although you have special processing for the session, passed in as a parameter but not on your server side, it is recommended that you go to debug mode to track whether the servers are getting the parameters correctly and load the session successfully. There is also a problem, if you currently open the URL is the same as the URL you submitted form, but also remember to add a random number.

The above is for thinkphp under the use of Uploadify plug-ins Firefox upload 302 error solution, I hope to help you learn.

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.