spires Posted September 12, 2006 Share Posted September 12, 2006 Hi, I'm trying to delete a image out of a folder on my server, I've got the line of code to do this but i cant seem to get it to work with variables, Any help please.[code]$sel_sql = "SELECT * FROM thumb WHERE thumb_id='$id'";$sel_query = mysql_query($sel_sql) or die ('could not select image name');$sel_row = mysql_fetch_array($sel_query);$thumb_name = $sel_row['new_img_name'];unlink("$thumb_name");$del_sql = mysql_query("DELETE FROM thumb WHERE thumb_id='$id' LIMIT 1");[/code]Thanks Quote Link to comment https://forums.phpfreaks.com/topic/20536-unlinkimagename/ Share on other sites More sharing options...
HuggieBear Posted September 12, 2006 Share Posted September 12, 2006 If you echo $thumb_name do you get the desired file name?Are you specifying the whole path, you may want to make sure if you're not in the same directory that you do this.RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20536-unlinkimagename/#findComment-90607 Share on other sites More sharing options...
paul2463 Posted September 12, 2006 Share Posted September 12, 2006 Hi Spiresjust a thought, in other PHP functions such as echo, you miss out the quote marks for variables i.e[code]echo("$thumb_name")[/code]whould print out[quote] $thumb_name //not the variable value [/quote]maybe its the same with unlink, try[code] unlink($thumb_name);[/code]hope that helpsPaul Quote Link to comment https://forums.phpfreaks.com/topic/20536-unlinkimagename/#findComment-90610 Share on other sites More sharing options...
spires Posted September 12, 2006 Author Share Posted September 12, 2006 Thanks for your comments. I got it working, My own stupid fault. I didnt attach the folder it was in. This deletes out of the database and folder at the same time.[code]$sel_sql = "SELECT * FROM thumb WHERE thumb_id='$id'";$sel_query = mysql_query($sel_sql) or die ('could not select image name');$sel_row = mysql_fetch_array($sel_query);$thumb_name = $sel_row['new_img_name'];unlink('thumb2/'.$thumb_name.'');unlink('thumb2_orig/'.$thumb_name.'');$del_sql = mysql_query("DELETE FROM thumb WHERE thumb_id='$id' LIMIT 1");[/code]Hope someone else find this handy. Quote Link to comment https://forums.phpfreaks.com/topic/20536-unlinkimagename/#findComment-90622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.