note 70166 added to function.ftp-nlist
| From: | fx dot menard at pleasenospam dot free dot fr | Date: | Thu, 05 Oct 2006 09:35:55 +0000 |
| Subject: | note 70166 added to function.ftp-nlist | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118084@lists.php.net to get a copy of this message | ||
A derived use of ftp_nlist function: determine if a given path exists and is a directory or a plain
file (this is not easy with basic ftp functions). This code doesn't issue any warning or error.
It makes use of ls option -d for efficiency, and -F to append a slash if the retrieved path is a
directory.
<?php
// returns information on a given ftp path
// 0 if path does not exist
// 1 if path is a file
// 2 if path is a directory
function ftp_pathtype( $conn, $path )
{
$res = ftp_nlist( $conn, "-dF " . $path );
if ( isset( $res[0] ) and
strlen( $res[0] ) )
{
if ( $res[0][ strlen( $res[0] )-1 ] === "/" )
// a directory
return 2;
else
return 1;
} else
return 0;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 217.174.201.226 (proxied: 128.2.123.225)
----
Manual Page -- http://www.php.net/manual/en/function.ftp-nlist.php
Edit -- https://master.php.net/note/edit/70166
Del: integrated -- https://master.php.net/note/delete/70166/integrated
Del: useless -- https://master.php.net/note/delete/70166/useless
Del: bad code -- https://master.php.net/note/delete/70166/bad+code
Del: spam -- https://master.php.net/note/delete/70166/spam
Del: non-english -- https://master.php.net/note/delete/70166/non-english
Del: in docs -- https://master.php.net/note/delete/70166/in+docs
Del: other reasons-- https://master.php.net/note/delete/70166
Reject -- https://master.php.net/note/reject/70166
Search -- https://master.php.net/manage/user-notes.php