Kavya Shree Kavya Shree - 24 days ago 11
PHP Question

Why is_dir() function is not checking case sensitive in CPanel server

I tried this code in localserver, It works correcly if my directory is having that foldername already and it won't accept the same folder to create, but if I uploaded the part in server.

If the directory is having foldername with Alto and new folder I tried name with alto Its just created why is it.

If anyone knows the solution.
enter image description here

<?php
$folder_type=$_POST['folder_type'];
$folder_name=$_POST['folder_name'];
$images="images";
$path="../../".$folder_type."/".$folder_name;
if (!is_dir("../../".$folder_type."/".$folder_name)) {
mkdir("../../".$folder_type."/".$folder_name);
mkdir("../../".$folder_type."/".$folder_name."/".$images);
$content = file_get_contents('../../default_code.php');
$fp = fopen($path . "/$folder_name.php","wb");
fwrite($fp,$content);
fclose($fp);
}
else
{
echo "0";
}
chmod("../../".$folder_type."/".$folder_name, 0777);
?>

Answer

To rule out this condition at all. Please use strtolower when creating a directory. That means use this:

$folder_name=strtolower($_POST['folder_name']);

Like this in future, your all folders will be in lowercase and there would be no chance of contradiction.

I hope it helps

Comments