Jump to content


Photo

unlink('imagename')?


  • Please log in to reply
3 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 12 September 2006 - 06:25 PM

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.

$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");

Thanks
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 12 September 2006 - 06:47 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 12 September 2006 - 06:51 PM

Hi Spires

just a thought, in other PHP functions such as echo, you miss out the quote marks for variables i.e
echo("$thumb_name")
whould print out

$thumb_name //not the variable value

maybe its the same with unlink, try

unlink($thumb_name);

hope that helps
Paul
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#4 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 12 September 2006 - 07:18 PM

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.
$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");

Hope someone else find this handy.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users