Yes, I've spent so many time on deleting the folder with space. It worked for folder without space but not with spaces.
Note : I'm working on linux machine.
I've tried the following with so many way but ended in failure
Code: Select all
<?php
//shell_exec("mkdir 2003-05-29\ P\ UT");
$dir = "2003-05-29\\ P\\ +\\ UT";
$file = "PICT0011.jpg";
$path_to_file = $dir."/".$file;
if(!file_exists($dir)) { shell_exec("mkdir $dir");}
if(!file_exists($path_to_file)) { shell_exec("touch $path_to_file"); }
if(file_exists($path_to_file))
print $path_to_file;
shell_exec("chmod 755 $dir");
shell_exec("chmod 755 $path_to_file");
print shell_exec("ls -lth $dir/");
if(shell_exec("rm -rf $path_to_file")){
print "deleted ". $path_to_file;
}else{
print "error occured!";
}
?>
Output :
Code: Select all
total 0
-rwxr-xr-x 1 root root 0 2006-11-24 17:33 PICT0011.jpg
error occured!
But the following works if the folder is given without space like :
Code: Select all
<?php
//shell_exec("mkdir 2003-05-29\ P\ UT");
$dir = "2003-05-29";
//$dir = addslashes($dir);
$file = "PICT0011.jpg";
$path_to_file = $dir."/".$file;
//if(!file_exists($dir)) { mkdir($dir); }
if(!file_exists($dir)) { shell_exec("mkdir $dir");}
if(!file_exists($path_to_file)) { shell_exec("touch $path_to_file"); }
if(file_exists($path_to_file))
print $path_to_file;
//chmod($dir, 0777);
//chmod($path_to_file, 0777);
shell_exec("chmod 755 $dir");
shell_exec("chmod 755 $path_to_file");
print shell_exec("ls -lth $dir/");
if(unlink("$path_to_file")){
print "deleted ". $path_to_file;
}else{
print "error occured!";
}
?>
Output :
Code: Select all
2003-05-29/PICT0011.jpgtotal 0
-rwxr-xr-x 1 root root 0 2006-11-24 17:36 PICT0011.jpg
deleted 2003-05-29/PICT0011.jpg
Dibyendra