我有什麼動態變化:我使用uploadify上傳企業內部網應用程序,我寫的文件文件上傳插件位於Web根目錄忽略到目標文件夾
。
我需要將文件上傳到屬於一個用戶(動態創建的目錄)的目錄。
我顯然是不正確的解決方案:)
在我的任何用戶登錄後他創建一個文件夾(標題爲USER_ID)。
現在uploadify.php看起來像這樣:
session_name("test_tool_cookie");
session_start();
$targetFolder = '/test_tool/app/webroot/uploadify/' . $_SESSION['Auth']['User']['user_id']; //Relative to the root
//the 3 lines above are my only change to the script
//$targetFolder = '/test_tool/app/webroot/uploadify/tmpFile'; //this was here before my changes
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('html' , 'docx', 'pdf', 'xls', 'xlsx', 'txt'); // 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.';
}
}
的問題
以上腳本將無法上傳文件到文件夾(檢查和 不會上傳該文件在其他地方)。
如果我改變$的TargetFile靜態值,它工作正常。
- 會話值是正確的(但忽略)
還有什麼可以賺取回答問題
,如果你認爲一個好的multiupload插件(與我會將您的問題作爲一個答案簡單的描述),它很容易與Cake Cake集成,並且可以自定義,因此數據庫中的每個對象都可以擁有自己的文件夾。
請想想你的答案,對於這個問題的任何解決方案將有很大的幫助。
是否'$ _SESSION [ '驗證'] [ '用戶'] [ 'USER_ID']'抱一個字符串值如果你的用戶登錄?執行'$ _SERVER ['DOCUMENT_ROOT']。 $ targetFolder'存在並且是可寫的?如果您創建了該文件夾,那麼您的Web用戶的父文件夾是否可寫? –
使用is_writable方法檢查它,返回1.檢查會話,它包含一個數字(php是類型不敏感的,正確的)? http://php.net/manual/en/function.is-writable.php –
用is_string檢查SESSION,並返回1 –