2012-06-17 91 views
1

我在我的photocategories_controller.php文件中爲我的admin_add設置了以下代碼。這段代碼在我的CentOS開發服務器中非常適用。但是,當我將此文件上傳到我的生產服務器時,它不起作用。任何幫助將不勝感激〜CakePHP mkdir無法在生產服務器上工作

function admin_add() { 
    .... //Other code here 

    //On folder add, get its ID to be used as the name of the folder 
    $folderID = $this->Photocategory->getLastInsertId(); 

    //This directory is already created 
    $uploadDir = '/img/uploads/photos/'; 
    $serverRoot = $_SERVER['DOCUMENT_ROOT']; 

    //Folder location to be created. When I print it I get 
    // /home/xxxxxxx/public_html/img/uploads/photos/16 === 16 being the last inserted ID 
    $directoryPath = $serverRoot.$uploadDir.$folderID; 

    //I CANNOT FIGURE OUT WHAT AM I DOING WRONG HERE. IT WORKS IN MY DEVELOPMENT 
    //SERVER, BUT NOT IN MY PRODUCTION SERVER  
    if(mkdir($directoryPath, 0777)){ 
     if(mkdir($directoryPath."/thumb", 0777)){ 
      $this->Session->setFlash('Success', 'default', array('class' => 'alert_success')); 
     }else{ 
      $this->Session->setFlash('Error creating thumb', 'default', array('class' => 'alert_error')); 
     } 
    }else{ 
     $this->Session->setFlash('Error Creating Directory', 'default', array('class' => 'alert_error')); 
    } 
+4

大膽猜測:權限問題。顯然你的www數據不允許在這個文件夾中寫入。 –

回答

0

解決!我不知道爲什麼,但我的生產服務器沒有按照我的預期檢測到我的服務器根目錄。它看到$serverRoot = $_SERVER['DOCUMENT_ROOT'];作爲public_html文件夾。不過,我需要webroot文件夾。所以我用CakePHP自己的WWW_ROOT

相關問題