Jump to content

unlink('imagename')?


spires

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/20536-unlinkimagename/
Share on other sites

Hi Spires

just 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 helps
Paul
Link to comment
https://forums.phpfreaks.com/topic/20536-unlinkimagename/#findComment-90610
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/20536-unlinkimagename/#findComment-90622
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.