Image deleting problem...

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
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Image deleting problem...

Post by Czar »

I have a small problem with deleting an image. I have a small image gallery kinda thing in my webpage where users can upload images. Well, i now need a function to delete image. Details are passed via url to deleting script, which then deletes the references to current image from database and when deleting from db is successful i want it to delete that image from it's folder. I got messed up with those permeission things... 8O
I run the script now on my home server (localhost) and will soon upload it to my web server.

URL vars:

Code: Select all

<?php
delpic.php?id=4&cat=sra&file=img001.jpg
?>
After deleting from DB, this:

Code: Select all

<?php
$root = "F:/FOX/www/res/pics/";
  $dir = $_GET['cat']."/";
  $file = $_GET['name'];
  chmod($root.$dir, 0777);
  chmod($root.$dir.$file, 0777);
  unlink($root.$dir.$file);
?>
Those chmod things dosn't seem to work... have no idea of them anyway :P

I always get this error:

Warning: unlink() failed (Permission denied) in F:\FOX\www\res\delpic.php on line 55

How to do this properly? Thanks for any help.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try takign those chmods out and then just unlink($dir.$file);
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post by Czar »

Does not make any difference...
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

ahh... look your link:

"delpic.php?id=4&cat=sra&file=img001.jpg "

your code:

Code: Select all

$file = $_GET['name'];
Change $_GET['name'] to $_GET['file'] or change file in the URL to name... either way will work
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post by Czar »

Whoops...

So it was this kinda stupid mistake... again.
I've been tearing my hair for last few hours trying to solve this...

Thanks. No more coding today, better grab a few cold ones instead :)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

haha! It happens to me all the time too! So don't feel too stupid!
Post Reply