0

Just to start, yes I've read all the other Stack Overflow questions relating to this topic, but none of them provided me with a solution. One had a promising link that turned about to be dead. Apparently the entire swfupload forum doesn't exist anymore.

My problem is of course relating to passing my session variables to the actual PHP that processes the upload and inserts a line into a MySQL database. Two of the fields in that SQL line are session variables from the logged in user.

Based on the documentation and what I read from other threads, this is my code (or the relevant parts):

This is my javascript code from the main upload page. There is more but this is what's relevant. This code is a part of a $content variable that I use in a template function so its PHP syntax. Note, when I check this code in the browser it renders the correct values there.

var swfu;

window.onload = function() {
    var settings = {
        flash_url : "js/swfupload/swfupload.swf",
        upload_url: "process_upload.php",
        post_params: {
            "user_id" : "'.$_SESSION['user_id'].'",
            "school_id" : "'.$_SESSION['school_id'].'"
        },
        file_size_limit : "1000 MB",
        file_types : "*.wmv; *.mpg; *.avi; *.vob; *.mov; *.m4v; *.mpeg; *.mkv; *.flv; *.3gp",
        file_types_description : "All Files",
        file_upload_limit : 10,

Now, in my process_upload.php file if I do this:

$user_id = $_POST['user_id'];
$school_id = $_POST['user_id'];

Then use those variables in a query:

mysql_query("INSERT INTO table SET name='".$file_name."', school_id='".$school_id."', user_id='".$user_id."'") or die(mysql_error());

The query is successful and I get an entry in the database, but it doesn't fill in user_id and school_id and my error log shows Undefined Index error on that line.

4

1 回答 1

0

所以显然我缺少的是 process_upload 页面上的会话 ID。所以我这样做了,它现在似乎承载了我的会话值。

上传页面:

        post_params: {
            "PHPSESSID" : "'.session_id().'",
            "user_id" : "'.$_SESSION['user_id'].'",
            "school_id" : "'.$_SESSION['school_id'].'"
        },

流程页面:

if (isset($_POST["PHPSESSID"])) {
    session_id($_POST["PHPSESSID"]);
} else if (isset($_GET["PHPSESSID"])) {
    session_id($_GET["PHPSESSID"]);
}

session_start();

$user_id = $_POST['user_id'];
$school_id = $_POST['school_id'];

然后我在查询中使用这些变量,我们都很好!

于 2012-07-01T00:27:32.320 回答