Hello, I would like your help to solve the following problem. And if possible help me understand what happens
Code:
$FTP_HOST = "ftp.exemplo.com";
$FTP_USER = "usuario";
$FTP_PASS = "senha";
$cHandle = ftp_connect($FTP_HOST) or die("O Servidor não pode se conectar ao FTP");
$login_result = ftp_login($cHandle, $FTP_USER, $FTP_PASS) or die("O Servidor não pode logar-se no FTP!");
$user['Nome'] = 'ftp://usuario:[email protected]/diretorio/arquivo.ini'; //aqui está o meu problema.
if (!file_exists($user['Nome'])) {
echo 'Arquivo Inexistente!';
} else
{
echo 'Arquivo Existente!';
}
Well, this is the code that should work, but it does not work. If I type in my browser: ftp: // username: [email protected]/directional.file.ini The file opens and shows the data it contains. If I use it in PHP it does not even recognize that the file is there, I would like to know how I can resolve it.
To check if the file exists I could use:
$cHandle = ftp_connect($FTP_HOST) or die("O Servidor não pode se conectar ao FTP");
$login_result = ftp_login($cHandle, $FTP_USER, $FTP_PASS) or die("O Servidor não pode logar-se no FTP!");
ftp_login($cHandle,"usuario","senha");
$dir = "/diretorio/";
$arq= "arquivo.ini";
$check_file_exist = $dir.$arq;
$contents_on_server = ftp_nlist($cHandle, $dir);
if (!in_array($check_file_exist, $contents_on_server))
{
echo 'Arquivo Inexistente';
}else
{
echo ' Arquivo Existente';
}
It works, except that in this second form, it only checks the existence of the file and I would like it to check the file as it would open in the first option, I already searched, I tried, and I could not do it if someone could help me thank you.
So .. How can I make php open and read the file via ftp, the same way it opens the first try above?