2013-02-06 128 views
0

我有什麼動態變化:我使用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集成,並且可以自定義,因此數據庫中的每個對象都可以擁有自己的文件夾。

請想想你的答案,對於這個問題的任何解決方案將有很大的幫助。

+0

是否'$ _SESSION [ '驗證'] [ '用戶'] [ 'USER_ID']'抱一個字符串值如果你的用戶登錄?執行'$ _SERVER ['DOCUMENT_ROOT']。 $ targetFolder'存在並且是可寫的?如果您創建了該文件夾,那麼您的Web用戶的父文件夾是否可寫? –

+0

使用is_writable方法檢查它,返回1.檢查會話,它包含一個數字(php是類型不敏感的,正確的)? http://php.net/manual/en/function.is-writable.php –

+0

用is_string檢查SESSION,並返回1 –

回答

1

你有沒有嘗試與您的表單數據發送會話名稱像的例子here

0

你應該檢查什麼$_SERVER['DOCUMENT_ROOT']回報。

因爲如果它返回,可以說/home/your_username/public_html/test_tool/app/webroot,我相信這是發生了什麼,並且您正在添加/test_tool/app/webroot/uploadify/,您將永遠不會獲取要上載的文件。

從我的角度來看,你應該做到以下幾點,離開一切的是:

// As long as $_SESSION['Auth']['User']['user_id'] has a value, it should work. If not, statically place a number there like /uploadify/1 to see if it works 
$targetFolder = '/uploadify/' . $_SESSION['Auth']['User']['user_id']; //Relative to the root 
+0

當我靜態地嘗試它時,它工作正常,所以我想這個問題將與會議閱讀(這在另一個。在這個文件夾中的PHP文件返回一個正確的值)。 我在週三沒有嘗試lp1051的鏈接建議,今天它沒有真正的工作,將很快編輯我的問題。 –

相關問題