unlink () question, unable to delete thumbnail picture

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

unlink () question, unable to delete thumbnail picture

Post by cooler75 »

hello,
after when i have this problem solved, i will have a complete upload script.

I have a script that upload image to the directory, image info to the database. Everything works just fine until when i tried to delete an image.

When i click delete, the image info is deleted from the database, the original image is deleted from the directory, but the image thumbnail is unable to delete.

this is my delete image script:

Code: Select all

//DELETE AN IMAGE

if ($deleteimage != "")

	{
        $query = "DELETE FROM tbl_thumb WHERE ((ID = $deleteimage) AND (owner='$current_user'))";
        if (!mysql_query ($query, $link) ){die (mysql_error());}
        unlink("$listings_upload_path/$file_name");
        unlink("$listings_upload_path/$thumb_file_name");
        Print "<table cellspacing=5 cellpadding=5 width=100%><tr><td>";
        print "<table border=0 cellspacing=0 cellpadding=5 width=100%><tr><td height=28>";
        print "<font face="Verdana" size=2><b>$file_name and thumb image have been successfully removed.</b></font>";
        print "</td></tr></table>";
        Print "</td></tr></table><br><br>";
        }
and i get this error message:

Code: Select all

Warning: unlink() failed (Is a directory) in /home/virtual/site58/fst/var/www/html/test/upload.php on line 312
and line 312 is :

Code: Select all

unlink("$listings_upload_path/$thumb_file_name");
when i browse the directory with FTP, i notice that the original image is removed, but the thumb is still there.

I would like to find out what went wrong there? what do i have to check in order to get this right?

thank you very much
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

echo "deleting '$listings_upload_path/$file_name' ....<br/>";
unlink("$listings_upload_path/$file_name")
echo "deleting '$listings_upload_path/$thumb_file_name' ....<br/>";
unlink("$listings_upload_path/$thumb_file_name");
probably $thumb_file_name is not set.
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

Hello guru,

yeah, followed your instruction and got this error msg:
deleting '/home/virtual/site58/fst/var/www/html/test/images/listing_images/bg.jpg' ....
deleting '/home/virtual/site58/fst/var/www/html/test/images/listing_images/' ....

Warning: unlink() failed (Is a directory) in /home/virtual/site58/fst/var/www/html/test/upload.php on line 315
bg.jpg and thumb image have been successfully removed.
Looks like $thumb_file_name is not set yet, there is no value.
what do i have to do? How do we know if it's set? $file_name isnt set either, but no problem?

please advise and thank you
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$file_name isnt set either, but no problem?
  • from what I see
  • $listings_upload_path is '/home/virtual/site58/fst/var/www/html/test/images'
  • $file_name is 'bg.jpg'
  • and only $thumb_file_name isn't set
what ever you do to set $file_name I suggest you do nearly the same with $thumb_file_name ;)
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

hey guru,
thanks, my fault, wasnt careful enough

i forgot to add this line to the link:

Code: Select all

thumb_file_name=$image_rowїthumb_file_name]
thanks so much for your help :lol:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please read http://www.php.net/manual/en/language.types.array.php#language.types.array.donts and use

Code: Select all

thumb_file_name=$image_rowї'thumb_file_name']
thumb_file_name is a string-literal used as array index so you have to quote it ;)
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

hi guru,
i dont use quote for any of those..

but i tried with your suggestion to quote them and i got the following error message:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/virtual/site58/fst/var/www/html/test/upload.php on line 265
line 265 is

Code: Select all

img src='$listings_view_images_path/$image_rowї'thumb_file_name']'
so, not too sure why we need to quote it!? :roll:

And i am using PHP Version 4.2.2

thank you
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

probably you have something like

Code: Select all

echo "img src='$listings_view_images_path/$image_rowї'thumb_file_name']'"
(otherwise there would be no replacement ;) )
And since you already are in a string literal you must not open another inside by quoting the index. You can interrupt the literal parsing by using { }, so there are two valid ways

Code: Select all

//either
echo "img src='$listings_view_images_path/$image_rowїthumb_file_name]'";
// or
echo "img src='$listings_view_images_path/{$image_rowї'thumb_file_name']}'";
but http://www.php.net/manual/en/language.types.array.php#language.types.array.donts refers to variables outside a string literal, like

Code: Select all

$var = $arrї'idx'];
in-string-replacement is described at http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing

btw: Guru does not refer to knowledge at this board ;)
see also: user definitions
Post Reply