Page 1 of 1

Image deleting problem...

Posted: Sun May 30, 2004 11:00 am
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.

Posted: Sun May 30, 2004 11:10 am
by Illusionist
try takign those chmods out and then just unlink($dir.$file);

Posted: Sun May 30, 2004 11:22 am
by Czar
Does not make any difference...

Posted: Sun May 30, 2004 11:26 am
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

Posted: Sun May 30, 2004 12:13 pm
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 :)

Posted: Sun May 30, 2004 7:03 pm
by Illusionist
haha! It happens to me all the time too! So don't feel too stupid!