I have problem in creating folder in server (centos), there is a form with file upload field, where the ajax callback always returned error as:
Warning: mkdir(): Permission denied in /home/sitename/public_html/inc/callback/request_update.php on line 90
Warning: move_uploaded_file(../../images/listing/16/805202.jpg): failed to open stream: No such file or directory in /home/sitename/public_html/inc/callback/request_update.php on line 95
Warning: move_uploaded_file(): Unable to move '/tmp/phpnrtrdp' to '../../images/listing/16/805202.jpg' in /home/sitename/public_html/inc/callback/request_update.php on line 95
and its indicate the line in file request_update.php
is causing the error:
mkdir($output_dir, 0755, true);
request_update.php:
if(isset($_FILES['files'])){
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name){
$file_name = $key.'_'.$_FILES['files']['name'][$key];
$file_size = $_FILES['files']['size'][$key];
$file_tmp = $_FILES['files']['tmp_name'][$key];
$file_type = $_FILES['files']['type'][$key];
//explode fine name and extension
$ext_x = explode('.', $_FILES['files']['name'][$key]);
$ext = strtolower(end($ext_x));
$file_name = str_replace('.'.$ext, '', $_FILES['files']['name'][$key]);
//new file name
$output_dir = '../../images/listing/'.$list_id;
$new_file_name[] = rand(1, 999999).'.'.$ext;
$pathfile = $output_dir.'/'.end($new_file_name);
// create directory if does not exist
if(is_dir($output_dir) == false){
mkdir($output_dir, 0755, true); /*this is where error indicate*/
}
if(is_dir($pathfile) == false){
if(move_uploaded_file($file_tmp, $pathfile)){
//watermark
$water_path = '../../images/watermark.jpg';
$watermark = WideImage::load($water_path);
//resize original image
WideImage::load($pathfile)->resize(300, 360)->merge($watermark, '50% – 25', '100% – 40', 80)->saveToFile($pathfile);
}
}
}
}
I've been tried the same code run in another shared server and even localhost, the folder can be created fine all the time, what is happen?