Sorry for interrupting, I was trying to create batch folders using PHP codes on my LAMP server. My codes is attached below:
enter code here
<?php
**//sample .html template**
$out1 =
"<html>
<head>
<title>Test Page</title>
</head>
<body>
GGYY der
</body>
</html>";
**//fetch folder names from .txt file under my website main directory**
$file_name="DirName.txt";
$fp=fopen($file_name,'r');
$content = array();
$i =0;
while(!feof($fp)){
$buffer=fgets($fp,4096);
$content[$i]=$buffer;
$i++;
}
**//create folders base on $content size**
for($j=0; $j<sizeof($content); $j++){
if(mkdir($content[$j],0777))
echo "folder created"."<br>";
else
echo "fail to create"."<br>";
**//create a .html file in created folder**
$mycat = fopen ("./$content[$j]/mycat.html","w");
**//use copy template into mycat.html**
fwrite($mycat, $out1);
fclose ($mycat);
echo "Success";
}
fclose($fp);
?>
Based on my codes, it seems like that I did created several folders at one click, but when I try to access these folders through SSH FTP connection, it shows that "Directory /xxx/www/xxx/Aquarius : no such file or directory" Even if there are folder icons on that directory.
And I tried to connect to my server through Ubuntu command line, cd to that dedicate directory and enter ls command, It shows that all folders I just created with "??" mark right after the folders name. And I can't either delete the folder or access the folder.
I already spend all day on this and can't find an answer. It'll be really appreciated if anyone can help me out.
I suspect you have hidden chars in there that make the dire names mess up. Probably \r\n if that file was created on Windows.
A trim() of each line before creating the folder might be a good fix.
Now to delete directories with weird names, look into ls -i
to show the inode number, and find -inum <NUMBER> -exec rmdir {} \;
to flush them out.