newbie Q - file deletions and permissions problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

newbie Q - file deletions and permissions problem

Post by Coco »

im trying to delete a text file. Nothing fancy.

No matter what I do, the script always returns permission denied. Chmod set to 777 via ftp.
ive read thru the past posts, and tried stuff ive come accross, but it still wont do it :?

Ive tried:

Code: Select all

<?php
// now delete counter file
$filename = $_SERVER["DOCUMENT_ROOT"] . '/test.txt';
if (file_exists($filename))
{
	chmod($filename, 0777);
	unlink($filename);
	echo 'deleted... apparently';
} 

-------------
// now delete counter file
$filename = $_SERVER["DOCUMENT_ROOT"] . '/test.txt';

if (file_exists($filename))
{
	unlink($filename);
	echo 'deleted... apparently';
} 

------------
// now delete counter file

$filename = './test.txt';
if (file_exists($filename))
{
	unlink($filename);
	echo 'deleted... apparently';
} 


?>
Whats even stranger, is that the chmod command itself is blocked by the server (operation not permitted)
What am i doing wrong? Do i need to get my host to change the setup?
other than doing a chown, i dont know what else to try
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

You might not have chmod permissions, check that with your host...
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

maybe so, but I have the permissions in ftp, and had previously set the files permissions to 777
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

man chmod wrote: Only the owner of a file or the super-user is permitted to change the mode of a file.
PHP manual wrote: Note: The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access.
ragnew
Forum Newbie
Posts: 5
Joined: Mon Aug 23, 2004 2:40 pm

Post by ragnew »

How do you make the end user the same as the file user so I can avoid the same problem?
Post Reply