Page 1 of 1

unlink(): SAFE MODE Restriction in effect! Help

Posted: Fri Apr 29, 2005 8:03 am
by asterinex
Hello everyone,

I have a datingsite with users who can upload pictures to a certain directory.

Now I'm working on a administration page where I can delete users from my site.
Programming the part of deleting the picture uploaded by the user. I get this error :

unlink(): SAFE MODE Restriction in effect. The script whose uid is 20136 is not allowed to access / owned by uid 0 in


When the user uploads the file i chmod the file with 0777.
Wenn the user loggs in , he can delete is own picture. But wenn I try it. I get the error.

I working on a shared server with safe mode on. There is no ini file available.

What can I do to delete the picture from a php script ?

Thanks in advance

Posted: Fri Apr 29, 2005 10:36 pm
by hanji
unlink(): SAFE MODE Restriction in effect. The script whose uid is 20136 is not allowed to access / owned by uid 0 in
This is interesting.. I think your script is not looking in the right place for the unlink. UID of 0 is 'root'.. I'm assuming that files being uploaded should be owned by a standard user or 'apache' or 'nobody'

So it's saying that your script (20136 is the owner of that file) is trying to delete a file that is owned by (0 who is root).. and it says that is not allowed to access / which is the root filesystem. Are you adding a complete path in your unlink() call?

Code: Select all

unlink('/path/to/image/file/imagefile.jpg');
hanji

Posted: Sat Apr 30, 2005 6:33 am
by asterinex
This is the the function that I call :
the picture of guestbook is stored in http://www.mydomain.com/community/logos
the picture name is stored in the db(logolink) fe. johnny.jpg

Code: Select all

function PHP_Delete_Guestbook_Picture($name)
{
       include (&quote;conn.php&quote;);
	mysql_select_db($db1,$conn);
	$sql  		= &quote;SELECT logolink FROM users WHERE name='$name' LIMIT 1;&quote;;
	$result 	= mysql_query($sql,$conn);
       $myrow 		= mysql_fetch_array($result);
	if ($myrowї'logolink']!=&quote;&quote;)
	{	
		$filename	= &quote;/community/logos/&quote;.$myrowї'logolink'];
		echo &quote;try to delete &quote;.$filename.&quote;<br>&quote;;
		unlink($filename);
	}
}

Posted: Sat Apr 30, 2005 6:47 am
by shiznatix
or you can have php connect to your ftp with ftp_connect and then you can use the ftp commands to delete the file, thats how i usually get around the safemode problems.

Posted: Sat Apr 30, 2005 7:21 am
by asterinex
Already a lot of thanks for the reply's . I tried it with ftp connection
It is still not working.
Warning: ftp_delete(): Delete operation failed. in /srv/www/htdocs/web53/html/community/logos/delete_pic.php on line 17
could not delete
in my file line 17 = ftp_delete($conn_id, $filename)


This is the code i used :

Code: Select all

$ftp_server = "myserver";
 
$filename	= "/community/logos/johnny.jpg";
// set up basic connection
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// login with username and password
$login_result = ftp_login($conn_id, "user", "password") or die("Couldn't login to $ftp_server"); 

// try to delete $file
if (ftp_delete($conn_id, $filename)) {
 echo "$file deleted successful\n";
} else {
 echo "could not delete $file\n";
}

// close the connection
ftp_close($conn_id);

Posted: Sat Apr 30, 2005 8:36 am
by hanji
Try using 'complete' path as suggested for unlink...

Code: Select all

$filename	= "/srv/www/htdocs/web53/html/community/logos/".$myrow['logolink'];
echo "try to delete ".$filename."<br>";
unlink($filename);
HTH
hanji

SOLVED !

Posted: Sat Apr 30, 2005 10:58 am
by asterinex
Thanks everyone . unlink works fine with the full path !

I'm going to party tonight!

:D

Thanks alot!