Hi all, here i got a problem where i want to delete file uploaded..my script
just remove from database but not remove from directory.. how can i delete from database and directory at a same time?? Please help me..

Recommended Answers

All 5 Replies

this my delete code

<?php 
include 'connection/db_connect.php';
$attcid = $_GET['attcid'];
$username = $_GET['username'];

$sql="DELETE FROM attachment WHERE attcid = '$attcid'";
mysql_query($sql);

?>

try.. make sure the directory and the file name are properly assigned below.

if (file_exists($attcid."whatever.extensionOfFile"){
						@unlink($attcid."whatever.extensionOfFile") ;
					}
else{

echo "Are you kidding me? This file don't even exist. I already looked.";

}
commented: Useful post +6

thanks veedeoo for suggestion..still not work.. hurm.. :(

unlink works, if it doesn't then there's problem with your path, if you doubt it's functionality, try doing simple test, like unlink(test.php); putting unlink script and test.php into the same directory

thanks all!! it works!! when second try i change by calling the file name.. hurmm
thank you so much!! This my latest code.. :)

<?php
$fileName=$_GET['fileName'];
$sql="DELETE FROM attachment WHERE fileName = '$fileName'";
unlink("path".$fileName);
mysql_query($sql);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.