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. ???

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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);


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.