0

Am trying to get my script to read in a directory and search for a a file, if the file doesnt exist it should print"that it doesn't exist" then add Notinfolder in an array. Please assist

<?php
$connection = ftp_connect($server);

$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);

if (!$connection || !$login) { die('Connection attempt failed!'); }

echo "Connected"."<br>";
$newcontents = ftp_chdir($connection, 'public_html');
$newcontents = ftp_nlist($connection, ".");
$cart = array();
$datedone=date("m.d.y");
foreach ($newcontents as $v){
if($v == "test1.zip"){
echo "True";
$cart[0]="test1.zip";
break;
}
elseif ($v<>"test1.zip")
{
echo "Test1 doesn't exist";
$cart[0]="Failed:".$datedone;
break;
}
}
echo "<br>";
print_r(array_values($cart));
ftp_close($connection);
?>
2
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by tapuwa2002
0

The problem am having is that when the file is on the ftp server it still reads:"Test1 doesn't exist".Is there any other way I can achieve the same results to check if the file exists and put my results in an array for later use.

0

The problem am having is that when the file is on the ftp server it still reads:"Test1 doesn't exist".Is there any other way I can achieve the same results to check if the file exists and put my results in an array for later use.

0

I managed to try the following and it works. If anyone has a better way or quicker way I would appreciate any feedback.

if (in_array("test1.zip", $newcontents)) {
    echo "Got Test";
}
else
{
echo "Don't have Test";
}
echo "<br>";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.