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

后端 未结 6 1259
时光取名叫无心
时光取名叫无心 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:02

    Some suggestions:

    • Use ftp_size, which returns -1 if it doesn't exist: http://www.php.net/manual/en/function.ftp-size.php
    • Use fopen, e.g. fopen("ftp://user:password@example.com/somefile.txt", "r")
    • Use ftp_nlist, check to see if the filename you want is in the list: http://www.php.net/manual/en/function.ftp-nlist.php

提交回复
热议问题