Ver Mensaje Individual
  #6 (permalink)  
Antiguo 22/07/2009, 08:27
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Problema con un codigo con fileexists

Ok pues en todo caso el if que verifica el $filename debe ir fuera de la funcion. Me refiero a esto

Código php:
Ver original
  1. <?
  2.  
  3. // copiar.php?origen=Dir_origen&destino=Dir_destino
  4. $origen="Dir_origen";
  5. $destino="Dir_destino";
  6. $filename = '/path/to/foo.txt';
  7.  
  8. function copy_dir($origen,$destino)
  9. {
  10.    if (is_dir($destino))
  11.       echo "El directorio destino ya existe.<br>";
  12.    else
  13.       mkdir("$destino");
  14.    if ($vcarga = opendir($origen))
  15.    {
  16.       echo "Directorio: $origen<br><br>";
  17.       echo "Fichero(s):<br><br>";
  18.       while($file = readdir($vcarga))
  19.       {
  20.          if ($file != "." && $file != "..")
  21.          {
  22.             if (is_dir($origen."/".$file))
  23.             {
  24.                copy_dir($origen."/".$file,$destino."/".$file);
  25.             }
  26.             else
  27.             {
  28.                if(copy($origen."/".$file, $destino."/".$file))
  29.                   echo "<b>$file</b> se copió con éxito al directorio $destino .<br>";
  30.             }
  31.          }
  32.       }
  33.       closedir($vcarga);
  34.    }
  35. }
  36.  
  37. if (file_exists($filename)) {
  38.     header("Location: pagina_que_quiero_redirigir_si_existe.php");
  39. } else {
  40.     copy_dir($origen,$destino);
  41. }
  42. ?>