1

admin_add我的文件中有以下代码设置photocategories_controller.php。这段代码在我家里的 CentOS 开发服务器上运行良好。但是,当我将此文件上传到我的生产服务器时,它不起作用。任何帮助将不胜感激~

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

2 回答 2

0

解决了!我不知道为什么,但我的生产服务器没有像我预期的那样检测到我的服务器根目录。它被$serverRoot = $_SERVER['DOCUMENT_ROOT'];视为public_html文件夹。但是我需要这个webroot文件夹。所以我使用了 CakePHP 自己的WWW_ROOT.

于 2012-06-30T12:23:27.257 回答
0

为此,使用 API 函数 cakephp 文件夹很有用,使目录的创建更加安全和可控

更多信息在这里

http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html

于 2013-02-28T07:08:56.967 回答