define('UPLOAD_PATH_CAT', SITE_URL.'/yourPath');
if(isset($_FILES['categoryImg']['name']) && !empty($_FILES['categoryImg']['name'])):
if (!file_exists(UPLOAD_PATH_CAT)):
mkdir(UPLOAD_PATH_CAT, 0777, true);
$content = "No Direct Access!";
$fp = fopen(UPLOAD_PATH_CAT."/index.html","wb");
fwrite($fp,$content);
endif;
$fileParts = explode(".",$_FILES['categoryImg']['name']);
$ext = end($fileParts);
unset($fileParts[count($fileParts)-1]); // extension removed from file name;
/** File Name without extension **/
$fName = implode(".",$fileParts)."_".strtotime(date('Y-m-d H:i:s'));
/** File Name With Extension **/
$fName = preg_replace("/[!@#$%^&*()-+|{}\s]/","_",$fName);
$fileName = str_replace(" ","_",$fName.".".$ext);
move_uploaded_file($_FILES['categoryImg']['tmp_name'],
UPLOAD_PATH_CAT.$fileName);
$data['categoryImg']=$fileName;
if(isset($editPageId) && $editPageId!=''):
$bData=$this->common_model->getData($editPageId,'category','categoryId');
$unlinkUrl=UPLOAD_PATH_CAT."{$bData->categoryImg}";
if(file_exists($unlinkUrl)):
unlink($unlinkUrl);
endif;
endif;
endif;
if(isset($_FILES['categoryImg']['name']) && !empty($_FILES['categoryImg']['name'])):
if (!file_exists(UPLOAD_PATH_CAT)):
mkdir(UPLOAD_PATH_CAT, 0777, true);
$content = "No Direct Access!";
$fp = fopen(UPLOAD_PATH_CAT."/index.html","wb");
fwrite($fp,$content);
endif;
$fileParts = explode(".",$_FILES['categoryImg']['name']);
$ext = end($fileParts);
unset($fileParts[count($fileParts)-1]); // extension removed from file name;
/** File Name without extension **/
$fName = implode(".",$fileParts)."_".strtotime(date('Y-m-d H:i:s'));
/** File Name With Extension **/
$fName = preg_replace("/[!@#$%^&*()-+|{}\s]/","_",$fName);
$fileName = str_replace(" ","_",$fName.".".$ext);
move_uploaded_file($_FILES['categoryImg']['tmp_name'],
UPLOAD_PATH_CAT.$fileName);
$data['categoryImg']=$fileName;
if(isset($editPageId) && $editPageId!=''):
$bData=$this->common_model->getData($editPageId,'category','categoryId');
$unlinkUrl=UPLOAD_PATH_CAT."{$bData->categoryImg}";
if(file_exists($unlinkUrl)):
unlink($unlinkUrl);
endif;
endif;
endif;
No comments:
Post a Comment