View Full Version : Delete file from server

08-21-2009, 08:49 PM
Hello all,
i have a problem, i cannot delete a file from my server using php. i am using unlink() to delete the file, but its not posting the file name.

if($_REQUEST['action']=="del") {
$con = mysql_connect("localhost","root","") or die("sorry");
mysql_select_db("tblname", $con);
mysql_query("DELETE FROM db WHERE id={$_REQUEST['id']};");
// Here is the problem
$myfile = "file:////serverip/test/".$_REQUEST['filename']."";
//more code
//the link
( mysql code)
<a onclick=\"return confirm('Are You Sure?');\" href='P&A.php?action=del&id=".$row['id']."&file=".$row['filename']."'>Delete</a>

Now, the row gets deleted from mysql, but the file doesnt get deleted. it says that "unlink()" isnt working? When i hover over the "delete" button, i see the id and filename, then i guess its not getting passed through that. Please help

08-21-2009, 09:04 PM
file:/// the file protocol here means the file is on your computer not on your server.

To be more precise $myfile = "file:////serverip/test/"

08-21-2009, 09:38 PM
[file:////serverip] well i use that on a donwload link to download the file from a remote sharedrive. how should i write it then?? i dont think the file name is getting passed through the link.?

08-21-2009, 10:21 PM
PHP unlink() can only delete files on the server the script is being run on. If you wanted to delete a file on a remote server, you would need to use PHP's ftp functions.

Hope this helps.