Page 1 of 1

unlink() permission denied?

Posted: Wed Nov 22, 2006 11:49 pm
by dimovi

Code: Select all

/*
I have Apache 2.0 and PHP 5.1.4 on WinXP Pro
When I try to delete a file with unlink() it works fine if the directory does not contain characters such as '~', '+' etc.
Any idea why that is?
Does anyone know how to take care of that?

ex.
*/
unlink("Austin/2003-05-29 P + UT/PICT0011.JPG");   // would not work
unlink("Austin/2003-05-29 P UT/PICT0011.JPG");   // works

Posted: Thu Nov 23, 2006 4:42 am
by dibyendrah
Try

Code: Select all

unlink("Austin/2003-05-29\ P\ +\ UT/PICT0011.JPG");

It didn't work

Posted: Thu Nov 23, 2006 1:08 pm
by dimovi

Code: Select all

unlink("Austin/2003-05-29\ P\ +\ UT/PICT0011.JPG"); //does not work
// and neither does
unlink("Austin/2003-05-29 P \+ UT/PICT0011.JPG");

// the problem could not be in the spaces because it works fine when there is no '+'

Posted: Thu Nov 23, 2006 1:34 pm
by volka
Win xp pro, php 5.2.0, and I can't reproduce the error.
unlink("Austin/2003-05-29 P + UT/PICT0011.JPG");
file is gone.

Posted: Thu Nov 23, 2006 2:38 pm
by dimovi
I don't know what to do man.
It seems like nobody has had that problem.
It is probably something small, but...

Posted: Fri Nov 24, 2006 12:09 am
by dibyendrah
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 :oops:

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