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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.