Tema: ayuda unlink
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/03/2009, 10:16
Avatar de Ronruby
Ronruby
 
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: ayuda unlink

Sacado de los comentarios de la funcion unlink()

Cita:
To anyone who's had a problem with the permissions denied error, it's sometimes caused when you try to delete a file that's in a folder higher in the hierarchy to your working directory (i.e. when trying to delete a path that starts with "../").

So to work around this problem, you can use chdir() to change the working directory to the folder where the file you want to unlink is located.

<?php
$old = getcwd(); // Save the current directory
chdir($path_to_file);
unlink($filename);
chdir($old); // Restore the old working directory
?>
Cita:
I have founda that trying to delete a file using relative path like the example below does not work.

<?php
$do = unlink("../pics/$fileToDel");
if($do=="1"){
echo "The file was deleted successfully.";
} else { echo "There was an error trying to delete the file."; }
?>

I did not work at all, instead what I had to do was:

<?php
chdir('../pics/');
$do = unlink($fileToDel);
if($do=="1"){
echo "The file was deleted successfully.";
} else { echo "There was an error trying to delete the file."; }
?>

Then it worked !