'PHP mkdir() invalid argument
I am engaging in a project on windows server 2016, and the XAMPP/PHP version is 5.6(it needs an update I know), and something weird just happened:
I have an index.php that collects some parameters and post them to controller.php with ajax:
function scan_setting_confirm(){
const resp_array = [$("#year").val(),
$("#month").val(),
$("#cust_").val(),
$("#invoice_format").val(),
$("#select_save_path").val(),
$("#select_scan_path").val()
]
const radio_val = $("input[name='deduct']:checked").val();
if(resp_array.indexOf("")===-1 && radio_val !== undefined){
$.ajax({
url:'controller.php',
cache:false,
dataType:'html',
type:'POST',
data:{
task:'scan-setting',
year:$("#year").val(),
month:$("#month").val(),
cust:$("#cust_").val(),
invoice_format:$("#invoice_format").val(),
select_save_path:$("#select_save_path").val(),
select_scan_path:$("#select_scan_path").val(),
deduct:$("input[name='deduct']:checked").val()
},
error:function(e){alert(e);},
success:function(data){alert(data);}
});
}else{
alert('Please check if there is anything missed.');
}
}
const ele3 = document.getElementById('scan_setting_btn');
ele3.addEventListener('click',scan_setting_confirm);
and what controller.php does is:
function rename_pic(){
$year = $_POST['year'];
$month = $_POST['month'];
$cust = $_POST['cust'];
$deduct = $_POST['deduct'];
$format = $_POST['invoice_format'];
$scan = $_POST['select_scan_path'];
$save = $_POST['select_save_path'];
if($deduct=='2'){
$format = '88';
}
$save_dir_father = $save.'\\'.$cust;
$save_dir = $save.'\\'.$cust.'\\'.$year.'.'.str_repeat('0',2-strlen($month)).$month;
if(!file_exists($save_dir_father)){
mkdir($save_dir_father);
}
echo $_POST['select_scan_path'];
mkdir($save_dir);
echo $save_dir;
}
if ($_POST['task'] == 'scan-setting'){rename_pic()};
I tried to use those params to create directories, and this just casted an error:
But it seems pretty normal when echoing the variable,$save_dir.
I've tried encoding $_POST['select_scan_path'] and $_POST['select_save_path'] with BIG5 with iconv function, but it casted out another error:
iconv(): Detected an illegal character in input string
The weirdest thing is, if $_POST['select_scan_path'] and $_POST['select_save_path'] are encoded with big5 and the paths contains chinese characters, it works.
Codes just works fine on windows 11.
Any ideas? Thanks!
Solution 1:[1]
$save_dir_father = $save.'\\'.$cust;
$save_dir = $save.'\\'.$cust.'\\'.$year.'.'.str_repeat('0',2-strlen($month)).$month;
convert it to the following
$save_dir_father = $save.'\'.$cust;
$save_dir = $save.'\'.$cust.'\'.$year.'.'.str_repeat('0',2-strlen($month)).$month;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kolajo |
