I can not find the file with php

0

Could you help me with this:

<?php

$archivo="datos.txt";
$camino="datos/";
if(file_exists($camino.$archivo))
{
print " <p> Si existe el archivo $archivo en la carpeta $camino. </p>";
}
else
{
print " <p> No existe el archivo $archivo en la carpeta $camino. </p>";
}
?>
  

is a validation of the existence of a file but only goes through the   else I do not understand what is wrong, why do you say it does not exist?

    
asked by Agustin Coronel 13.10.2018 в 16:01
source

2 answers

0

Another solution can be using the following:

<?php
    $basePath = dirname(realpath(__FILE__));
    $archivo="datos.txt";
    $camino="/datos/";
    if(file_exists($basePath.$camino.$archivo))
    {
        print " <p> Si existe el archivo $archivo en la carpeta $camino.</p>";
    }
    else
    {
        print " <p> No existe el archivo $archivo en la carpeta $camino.</p>";
    }
?>
    
answered by 13.10.2018 в 20:20
0

Try this and let me know

<?PHP
	$archivo="datos.txt";
    $path = "./filespath/"; //set the path of the folder that contains the files
    $newpath=substr($path,2);//this takes out the ./ of the path
    $dir_handle = @opendir($path) or die("Unable to open $path");
    while ($file = readdir($dir_handle)){
    if($file!="." && $file!=".." && is_file($path.$file) && $file==$archivo){
		echo "se encontró el archivo";
		break;
	}
    }
?>
    
answered by 14.10.2018 в 22:26