How can I check if a file exists on a remote server using PHP?

后端 未结 6 1258
时光取名叫无心
时光取名叫无心 2020-12-02 20:47

How can I check if a specific file exists on a remote server using PHP via FTP connections?

6条回答
  •  清歌不尽
    2020-12-02 21:00

    A general solution would be to:

    1. Login using ftp_connect

    2. Navigate to the relevant directory via ftp_chdir

    3. Get the remote file list via ftp_nlist or ftp_rawlist

    4. Use in_array to see if the file was present in the array returned by ftp_rawlist

    That said, you could potentially simply use file_exists if you have the relevant URL wrappers available. (See the PHP FTP and FTPS protocols and wrappers manual page for more information.)

提交回复
热议问题