File Deletion script via SQL not working - help please.

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

File Deletion script via SQL not working - help please.

Post by simonmlewis »

Code: Select all

  $result = mysql_query ("SELECT photoprimary FROM products WHERE trash = 'yes'");
  while ($row = mysql_fetch_object($result))
     {
     $photoprimary = "<br/>Primary photo found and deleted.";
     $path = $_SERVER['DOCUMENT_ROOT'].'/images/productphotos/'.$row->photoprimary;
     $pathsmall = $_SERVER['DOCUMENT_ROOT'].'/images/productphotos/small/'.$row->photoprimary;
     $fh = fopen($path, 'w') or die("Sorry there is a problem");
     $fhsmall = fopen($pathsmall, 'w') or die("Sorry there is a problem.");
     fclose($fh);
     fclose($fhsmall);
     unlink($path);
     unlink($pathsmall);
     $primcomplete = "y";
     }mysql_free_result($result);
This is the script that looks for products with a photo in that field. If it finds it, it should delete the files from the server.
I get this error when running it:
Warning: fopen(/usr/local/psa/home/vhosts/domain.co.uk/httpdocs/images/productphotos/) [function.fopen]: failed to open stream: Is a directory in /usr/local/psa/home/vhosts/domain.co.uk/httpdocs/includes/a_productstrash.inc on line 71
Sorry there is a problem
The permissions of the folder and files are all set 777 properly.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply