steviez Posted February 27, 2007 Share Posted February 27, 2007 Hi, I am trying to have some files deleted from my server when a user closes their account, the only thing is it wont work! Here is my code so far: <?php include("../connect"); include("../header"); mysql_connect("$DBSERVER", "$USERNAME", "$PASSWORD"); mysql_select_db("$DATABASENAME","$db"); $filepath = "/home/steviez/YC9R5F01/htdocs/music4play/audio/"; $file = "SELECT FROM audio WHERE user_id = '68'"; if (! unlink ($file,$filepath)) { echo ("Couldn't delete file"); } else { echo ("Removed $file"); } ?> Any ideas? Link to comment https://forums.phpfreaks.com/topic/40429-solved-php-unlink/ Share on other sites More sharing options...
HaLo2FrEeEk Posted February 28, 2007 Share Posted February 28, 2007 Your file variable is in mysql_query format, but is not inside a mysql_query() function. Link to comment https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195619 Share on other sites More sharing options...
steviez Posted February 28, 2007 Author Share Posted February 28, 2007 how do i do this? im new to php Link to comment https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195622 Share on other sites More sharing options...
ikmyer Posted February 28, 2007 Share Posted February 28, 2007 <?php include("../connect"); include("../header"); mysql_connect("$DBSERVER", "$USERNAME", "$PASSWORD"); mysql_select_db("$DATABASENAME","$db"); // query the database for the file name first... how ever you want to do that... once you have that done continue below $file = "/home/steviez/YC9R5F01/htdocs/music4play/audio/" . $row['filename']; if (! unlink ($file)) { echo ("Couldn't delete file"); } else { echo ("Removed $file"); } ?> Link to comment https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195672 Share on other sites More sharing options...
steviez Posted February 28, 2007 Author Share Posted February 28, 2007 I tryed the code above but i cant get it working, here is my code now: <?php include("../connect"); include("../header"); $sql = "SELECT * FROM audio WHERE user_id = '68'"; $result = mysql_query($sql) or die(mysql_error()); $filename = "$result"; $path = '/home/steviez/YC9R5F01/htdocs/xxx/audio/'.$filename; if (!unlink($filename)) { echo ("Error deleting $filename"); } else { echo ("Deleted $filename"); } ?> Link to comment https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195722 Share on other sites More sharing options...
ikmyer Posted February 28, 2007 Share Posted February 28, 2007 try <?php include("../connect"); include("../header"); $sql = "SELECT * FROM audio WHERE user_id = '68'"; $result = mysql_query($sql) or die(mysql_error()); $row_result = mysql_fetch_assoc($result); $path = '/home/steviez/YC9R5F01/htdocs/xxx/audio/'.$row_result['fieldoffilename']; // update the field name... if (!unlink($path)) { echo ("Error deleting $path"); } else { echo ("Deleted $path"); } ?> Link to comment https://forums.phpfreaks.com/topic/40429-solved-php-unlink/#findComment-195738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.