Page 1 of 1

File Deletion script via SQL not working - help please.

Posted: Wed Nov 24, 2010 6:31 am
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.