Using UNLINK
Posted: Tue Feb 10, 2004 7:36 pm
Hello,
Thanks to all the professionals who help newbies like me!
I am trying to create a PHP page that will read a mysql table and then DELETE appropriate files on my (hosted) web server.
I have read the documentation about UNLINK, but I am confused about the method to authenticate the user to have permissions to delete files.
I found this code on the PHP documentation website:
But, I don't understand the line
Can I pass a username from (for example) a simple form? Or can I simply hardcode a username into my page (and store the page on a secured directory)?
Also, When I tried to implement the code above (possibly incorrectly), I received a "division by zero" error from the line
Is there somthing wrong there?
Anyways, I hope someone can shed some light on this for me, or point me to some other examples of how to code using the unlink command.
Thanks,
--TIM
Thanks to all the professionals who help newbies like me!
I am trying to create a PHP page that will read a mysql table and then DELETE appropriate files on my (hosted) web server.
I have read the documentation about UNLINK, but I am confused about the method to authenticate the user to have permissions to delete files.
I found this code on the PHP documentation website:
Code: Select all
<?php
// removes a file from the hard drive that
// the PHP user has access to.
$username = $_SERVER['REMOTE_USER']; // using an authentication mechanisim
$homedir = "/home/$username";
$file_to_delete = basename("$userfile"); // strip paths
unlink ($homedir/$file_to_delete);
$fp = fopen("/home/logging/filedelete.log","+a"); //log the deletion
$logstring = "$username $homedir $file_to_delete";
fputs ($fp, $logstring);
fclose($fp);
echo "$file_to_delete has been deleted!";
?>Code: Select all
<?php
$username = $_SERVER['REMOTE_USER']; // using an authentication mechanisim
?>Also, When I tried to implement the code above (possibly incorrectly), I received a "division by zero" error from the line
Code: Select all
<?php
unlink ($homedir/$file_to_delete);
?>Anyways, I hope someone can shed some light on this for me, or point me to some other examples of how to code using the unlink command.
Thanks,
--TIM