I am trying to upload photos in the folders from below php code but it creates new folder with year and month with 000 permission. Please help me. What is wrong with the below code? This is the code, please check and thanks for your time <?php require('include.php'); require('extras/Uploader.php'); function createFolder($subdir_path) { #$htaccess = "php_flag engine off" . "\r\n"; #$htaccess .= "RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp" . "\r\n"; #$htaccess .= "AddType text/plain .php .php .htm .html .phtml .pl .asp" . "\r\n"; #$mode = 0777; @mkdir($subdir_path, $mode = 0777); @chmod($subdir_path, $mode = 0777); #file_put_contents($subdir_path . '.htaccess', $htaccess); @mkdir($subdir_path."thmb", $mode = 0777); @chmod($subdir_path."thmb", $mode = 0777); #file_put_contents($subdir_path."thmb/" . '.htaccess', $htaccess); @mkdir($subdir_path."bigThmb", $mode = 0777); @chmod($subdir_path."bigThmb", $mode = 0777); #file_put_contents($subdir_path."bigThmb/" . '.htaccess', $htaccess); @mkdir($subdir_path."mobile_thmb", $mode = 0777); @chmod($subdir_path."mobile_thmb", $mode = 0777); #file_put_contents($subdir_path."mobile_thmb/" . '.htaccess', $htaccess); @mkdir($subdir_path."mobile_bigThmb", $mode = 0777); @chmod($subdir_path."mobile_bigThmb", $mode = 0777); #file_put_contents($subdir_path."mobile_bigThmb/" . '.htaccess', $htaccess); } global $ads_settings; $widthLimit = 1920; $heightLimit = 1080; $minWidth = $ads_settings['big_thmb_width']; $minHeight = $ads_settings['big_thmb_height']; $dir = '../images/listings/'; $subdir = date("Y-m"); if(!file_exists($dir . $subdir . DIRECTORY_SEPARATOR)) { createFolder($dir . $subdir . DIRECTORY_SEPARATOR); } $filename = date("YmdHis") . "-" . str_replace(" ", "", microtime()); $upload_dir = $dir . $subdir . DIRECTORY_SEPARATOR; $valid_extensions = array('gif', 'png', 'jpeg', 'jpg'); $Upload = new FileUpload('uploadfile'); $ext = $Upload->getExtension(); $Upload->newFileName = $filename . "." . $ext; $result = $Upload->handleUpload($upload_dir, $valid_extensions); if (!$result) { echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg())); } else { $path = $Upload->getSavedFile(); $imgsize = getimagesize($path); if ($imgsize[0] < $minWidth || $imgsize[1] < $minHeight) { echo json_encode(array('success' => false, 'msg' => " not uploaded, minimal size photo {$minWidth}x{$minHeight}")); exit(0); } require_once("smart_resize_image.module.php"); if ($imgsize[0] > $widthLimit || $imgsize[1] > $heightLimit) resize_image($path, $upload_dir . $filename . "." . $ext, $widthLimit, $heightLimit, $quality = 90, $crop = false); # create thmb resize_image($upload_dir . $filename . "." . $ext, $upload_dir . 'thmb' . DIRECTORY_SEPARATOR . $filename . "." . $ext, $ads_settings['thmb_width'], $ads_settings['thmb_height'], $quality = 90, $crop = true); # create bigThmb resize_image($upload_dir . $filename . "." . $ext, $upload_dir . 'bigThmb' . DIRECTORY_SEPARATOR . $filename . "." . $ext, $ads_settings['big_thmb_width'], $ads_settings['big_thmb_height'], $quality = 90, $crop = true); global $config_table_prefix; $mobile_settings = $db->fetchAssoc("SELECT * FROM {$config_table_prefix}mobile_settings"); if ($mobile_settings['enable_mobile_templates']) { # create mobile_thmb resize_image($upload_dir . $filename . "." . $ext, $upload_dir . 'mobile_thmb' . DIRECTORY_SEPARATOR . $filename . "." . $ext, $mobile_settings['mobile_thmb_width'], $mobile_settings['mobile_thmb_height'], $quality = 90, $crop = true); # create mobile_bigThmb resize_image($upload_dir . $filename . "." . $ext, $upload_dir . 'mobile_bigThmb' . DIRECTORY_SEPARATOR . $filename . "." . $ext, $mobile_settings['mobile_big_thmb_width'], $mobile_settings['mobile_big_thmb_height'], $quality = 90, $crop = true); } if (!empty($ads_settings['watermark']) && file_exists($upload_dir . $filename . "." . $ext)) { require_once("watermark_image.module.php"); add_watermark($upload_dir . $filename . "." . $ext, $ads_settings['watermark'], $ads_settings['watermark_position'], $ads_settings['watermark_transparency'], 90); } echo json_encode(array("success" => true, "file" => $Upload->getFileName(), "folder" => $subdir)); } PHP:
Haven't looked too closely at your code, but normally PHP shouldn't need to modify access on a created folder - as long as it's PHP that uploads files, it should have permissions already. For instance, when creating folders for a medialibrary I've made, it just creates folders, and then adds / removes files and folders without any trouble. Besides, you don't need a 7** permission to access and write files, you need a 644 permission (minimum) which lets the owner read/write, and other groups read
Hi. Try to uncomment the "#$mode = 0777;" line and use @mkdir($subdir_path, $mode); PHP: Also change all the other "$mode = 0777" to "$mode" in "mkdir" and remove all the "chmod" lines.
And second to that - never, EVER use 0777 on a publicly available site. EVER. It's a major security risk, especially if the check for allowed files aren't very good either.
Just try to use below code Here you must focus on the absolute path of the directory mkdir(ABS_PATH.'/images/galleries/'.$dir, 0777); chmod(ABS_PATH.'/images/galleries/'.$dir, 0777);