Is there a way to check if a a folder exists on the server using PHP Ftp functionality?
The file_exists() function checks whether a file or directory exists.
PHP Create File - fopen() The fopen() function is also used to create a file. Maybe a little confusing, but in PHP, a file is created using the same function used to open files. If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a).
PHP FTP IntroductionThe FTP functions give client access to file servers through the File Transfer Protocol (FTP). The FTP functions are used to open, login and close connections, as well as upload, download, rename, delete, and get information on files from file servers.
For PHP 5:
$folder_exists = is_dir('ftp://user:[email protected]/some/dir/path');
http://php.net/manual/en/function.is-dir.php : "As of PHP 5.0.0, this function can also be used with some URL wrappers."
http://php.net/manual/en/wrappers.ftp.php : [Support] "As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(), and is_dir()"
Try this:
if (ftp_nlist($ftp_stream, $new_folder) == false) {
ftp_mkdir($ftp_stream, $new_folder);
}
There is no 'exists' function for ftp connections in php.
You could try ftp_chdir and check the result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With