我需要使用會話變量作爲用戶名來指定uploadify(版本3.1)中的上載路徑。在uploadifive.php使用以下工作正常:會話變量沒有傳遞給uploadify.php
$uploadDir = 'media/' . $_SESSION["user_name"] . '/';
然而,在uploadify,當我使用相同的代碼,文件只是上傳到媒體文件夾(忽略用戶文件夾)。我在uploadify.php中回顯了$ _SESSION [「user_name」],並使用onUploadSuccess函數檢索了該函數,儘管開始會話,但實際上用戶名變量並未傳遞給uploadify.php。
這似乎很奇怪,這可以與uploadifive和不uploadify。我對PHP不太瞭解,並且很樂意爲此提供一些幫助。
我在下面列出了完整的uploadify.php腳本。
感謝,
尼克
<?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.';
}
}
?>
你可以'var_dump($ _SESSION)'只是爲了確保你實際存儲數據?我的意思是,你*在登錄時設定了數值,對嗎? – Sampson