I have a bit of code that downloads a remote file from another web server to the local web server. That part is easy:
Code: Select all
$srcRoot = "http://www.domain.com/thefile.pdf";
$desRoot = "../files/thefile.pdf";
copy($srcRoot,$desRoot);
This works fine, except when the source file is not available. The copy function, instead, downloads the 404 error page that comes up when trying to access a file that doesn't exist on the remote web server. How can I test to make sure the file is there before running the copy function?
I've tried is_file(), exists(), fopen(), is_readable(), file_exists() ... but they all lead to the same problem that there *is* readable content there, it's just a 404 page not the pdf I intended.