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();
$targetPath = 'media/' . $_SESSION["user_name"] . '/';
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetFile = $targetPath . $_FILES['Filedata']['name'];
$fileTypes = array('jpg','jpeg','gif','png');
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
?>