Question

This code runs when a user hits a delete button on my form. I am trying to copy a file, $picfile, from "/pics/" to "/pics/deletedrecordpics/" and then delete the orginal. Finally, delete the record from the database. Deleting the record from the databse works, but copying the file and deleting the original does nothing. There are no errors in the error log, so I am really confused as to why this code isn't running as I think it should.

   $sql = ("select picfile,title,author from $table where id=$delete");             
   $file=mysql_query($sql);
   $resrow = mysql_fetch_row($file); 
   $picfile = $resrow[0]; 
   $title = $resrow[1]; 
   $author = $resrow[2];     
   copy("pics/".$picfile,"pics/deletedrecordpics/".$author." - ".$title." - ".$picfile);    
   unlink("pics/".$picfile);
   $sql = ("DELETE FROM $table WHERE id=$delete");
   $result = mysql_query($sql);
Était-ce utile?

La solution

To make sure unlink should work check if your permissions are set correctly, and if unlink is available on the server installation.

Copy might not be working if "/deletedrecordpics" is a non existing directory, not created yet.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top