I have the following code setup for my admin_add in my photocategories_controller.php file. This code works great in my CentOS development server at home. However, it does not work when I upload this file to my production server. Any help will be appreciated~
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'));
}
SOLVED! I am not sure why, but my production server was not detecting my server root as I expected it to. It was seeing
$serverRoot = $_SERVER['DOCUMENT_ROOT'];as thepublic_htmlfolder. However I needed thewebrootfolder. So I used CakePHP’s ownWWW_ROOT.