Link wont separete

doing like /photos/ gives this error

Warning: unlink(/photos/1284149011_3.JPG) [function.unlink]: No such file or directory in C:\xampp\htdocs\rookierods\del_photos.php on line 49

Warning: unlink(/photos/thumbs/1284149011_3.JPG) [function.unlink]: No such file or directory in C:\xampp\htdocs\rookierods\del_photos.php on line 51

Who told you to use /photos/ ? I said to use ./photos/ (note the dot)

Does it work if you change define(“GALLERY_IMG_DIR”, “photos/”); to define(“GALLERY_IMG_DIR”, “./photos/”); ?
If not, PHP has no permission to delete files in the directory and you should change the permissions of that directory.

BTW, does PHP show warnings for the unlink()s ?

by defining do u mean like this
GALLERY_IMG_DIR = photos
because the photos are stored in the photos folder

Wait, now you’re using ?id= again, what happened to ?photos= ? :shifty:

Could you please post all the code you have so far? All these snippets that you are constantly changing are really starting to confuse me …

sorry yeah i changed
here the delete

 echo '<p><a href="del_photos.php?photos='.$row['photo_id'].'">delete</a></p>';

del_photos.php

<?php
define('ROOT_DIR', './');
define('PROPER', TRUE);



/**

* include common files

*/

include_once(ROOT_DIR. 'includes/common.inc.php');







// No album id has been selected

if (isset($_GET['photo_id']) && isset($_GET['photo_proper'])) {

   // get the image file name so we

   // can delete it from the server

   $sql = "SELECT photo_id, photo_proper

           FROM photos

           WHERE photo_id = {$_GET['photos']}

                 AND photo_proper = {$_GET['photo_proper']}";

   $result = mysql_query($sql)

             or die('Delete photo failed. ' . mysql_error());

   if (mysql_num_rows($result) == 1) {

      $row = mysql_fetch_assoc($result);



      // remove the image and the thumbnail from the server

      unlink(photos . $row['photo_proper']);

      unlink(photos . 'thumbs/' . $row['photo_proper']);



      // and then remove the database entry

      $sql = "DELETE FROM photos

              WHERE photo_id = {$_GET['photos']}";

      mysql_query($sql)

      or die('deletd photo failed. ' . mysql_error());

   }

  else{
   echo "file deleted";
 }
   

}

?>


nope still doesnt wrk? this how its looking now
this how the url says when i click delete.php… ohh and the photos are stored in photos folder
http://localhost/rookierods/del_photos.php?id=196

<?php
define('ROOT_DIR', './');
define('PROPER', TRUE);



/**

* include common files

*/

include_once(ROOT_DIR. 'includes/common.inc.php');







// No album id has been selected

if (isset($_GET['photo_id']) && isset($_GET['photo_proper'])) {

   // get the image file name so we

   // can delete it from the server

   $sql = "SELECT photo_id, photo_proper

           FROM photos

           WHERE photo_id = {$_GET['photos']}

                 AND photo_proper = {$_GET['photo_proper']}";

   $result = mysql_query($sql)

             or die('Delete photo failed. ' . mysql_error());

   if (mysql_num_rows($result) == 1) {

      $row = mysql_fetch_assoc($result);



      // remove the image and the thumbnail from the server

      unlink(photos . $row['photo_proper']);

      unlink(photos . 'thumbs/' . $row['photo_proper']);



      // and then remove the database entry

      $sql = "DELETE FROM photos

              WHERE photo_id = {$_GET['photos']}";

      mysql_query($sql)

      or die('deletd photo failed. ' . mysql_error());

   }

   

}

?>


Of course now that you changed the link to ?photos= instead of ?id=, $_GET[‘id’] will no longer but set, but instead $_GET[‘photos’] will be set.
Change $_GET[‘id’] in the queries to $_GET[‘photos’] and it should work.

Oh, and it’s got nothing to do with the unlink()s, those look fine to me :slight_smile:
Unless of course you haven’t defined “photos” anywhere …
Why did you change “GALLERY_IMG_DIR” to “photos” anyway?

the link that i have is this

 echo '<p><a href="del_photos.php?photos='.$row['photo_id'].'">delete</a></p>';

and i made the changes that u mention

$sql = "SELECT photo_id, photo_proper

         FROM photos

         WHERE photo_id = {$_GET['id']}

         "; 

$sql = "DELETE FROM photos

          WHERE photo_id = {$_GET['id']}"; 

but still not working so i wonder if its cz this

photos is the folder where the image stored in

    unlink(photos . $row['photo_proper']);
      unlink(photos . 'thumbs/' . $row['photo_proper']);
  1. Replace

if (isset($_GET['photo_id']) && isset($_GET['photo_proper']))

with


if (isset($_GET['photos']))

  1. Remove the following from the SELECT query: AND photo_proper = {$_GET[‘photo_proper’]} like I said in post #12

  2. Change photos in the unlink() functions to either GALLERY_IMG_DIR (assuming that is defined somewhere) or ‘photos/’

The link you have is <a href=“delete.php.php?id=‘.$row[‘id’].’”>, so the only thing that will be available in $_GET is ‘id’ (i.e. $_GET[‘id’]) and $_GET[‘photo_id’] and $_GET[‘photo_proper’] will not be available, because they are not set in the link.

With only the id the SELECT query should be as follows:


$sql = "SELECT photo_id, photo_proper
         FROM photos
         WHERE photo_id = {$_GET['id']}
         ";

And the DELETE query should be thus:


$sql = "DELETE FROM photos
          WHERE photo_id = {$_GET['id']}";

:slight_smile: