Jump to content

Archived

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

spires

unlink('imagename')?

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

Share this post


Link to post
Share on other sites
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.

Regards
Rich

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.