Session variable not passed to uploadify.php

I need to use a session variable for the username to indicate the upload path in uploadify (version 3.1). In uploadifive.php, using the following works fine:

$uploadDir = 'media/' . $_SESSION["user_name"] . '/';

However, when I download, when I use the same code, the files just load into the media folder (ignoring the user folder). I repeated $ _SESSION ["username"] in the uploadify.php file and got this using the onUploadSuccess function, and indeed, the username variable is not passed to uploadify.php, despite the start of the session.

It seems strange that this will work with uploadifive and not upload. I'm not too good at PHP and will be happy with some help with this.

I include the full uploadify.php script file below.

Thank,

Nick

<?php
session_start();
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/
// Define a destination
$targetPath = 'media/' . $_SESSION["user_name"] . '/';

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetFile = $targetPath . $_FILES['Filedata']['name'];

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}
?>
+3
2

.

Uploadify - , PHP script, , , PHP , , id $_GET/$_ POST, .

HTML:

<input type="hidden" id="sessionid" value="<?php echo session_id(); ?>" />

javascript:

$('#image').uploadify({
    'uploader'  : '/uploadify-v2.1.4/uploadify.swf',
    'script'    : '/uploadify.php',
    'cancelImg' : '/uploadify-v2.1.4/cancel.png',
    'folder'    : '/tempfiles',
    'auto'      : true,
    'multi'     : false,
    'scriptData': { 'session': $('#sessionid').val() }
});

PHP:

if ( isset($_REQUEST['session']) && !empty($_REQUEST['session']) ) {
    session_id($_REQUEST['session']);
}
session_start();

, auto_start ( ).

Uploadify.

+2

script, , . session_start(), , , $_SESSION["user_name"] , , , .

+1

All Articles