Jump to content

[SOLVED] Checking if a something is a directory or a file over ftp


curt22

Recommended Posts

I have a script that lists all the files/directorys in an ftp directory using a for loop and It works but i want it to say (file) beside files and (directory) beside directorys, I tried using is_dir($files[$i]) but it did not work how can i check if something is a file or a directory over ftp. If it helps Im using windows and php 5. ???

Thanks sspoke. i tried using is_file but i can't get it to work right this is what it outputs:

 

  • New Folder (this should be false)

bool(false)

  • New folder 2 (this should be false)

bool(false)

  • Untitled-1.php (this should be true)

bool(true)

  • Untitled-2.html (this should be true)

bool(false)

  • Untitled-3.php (this should be true)

bool(false)

  • test.txt (this should be true)

bool(false)

  • test2.txt (this should be true)

bool(false)

  • test3.txt (this should be true)

bool(false)

  • tree[1].html (this should be true)

bool(false)

 

Thanks everbody for your help I got it to work.

In case it helps someone else here is the code:

<?php 
// connect
$conn = ftp_connect("curtis.ifastnet.com") or die("Could not connect");
// login
ftp_login($conn,"curtis","******");
// get contents in array
$path = ".";
$contents = ftp_nlist( $conn, "-dF " . $path );
//convert to a string
$files_list = implode("'", $contents);
echo "<ul> Current files in directory ";
echo ftp_pwd($conn); 
// echo files in bullet list
$files = explode("'", $files_list);
for($i = 0; $i < count($files); $i++)
{

if (substr( $files[$i], -1) == "/" )
{
$files[$i] = str_replace( "/", " ", "$files[$i]") ;
$files[$i] = trim($files[$i]);
echo "<li>$files[$i] (directory)</li>";
}
else 
{
echo "<li>$files[$i] (file)</li>";
}
}
echo '</ul>';

ftp_close($conn);


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.