This is baffling me and I am tired of trying different variations to accomplish what should be such a simple task.
I have a folder in the main directory of the domainb called 'enroll_updates' that a file will be written to via CRON every night.
But I am going to put in a safety check to ensure that the file hasn't already been created for that day. (shouldn't ever happen, but just in case)
All I need to do is find out if that particular .csv file exists in that folder.
This is what I have: But it always tells me that the file exists, even when I change the name in the query to something that doesn't.
I actually have two of the attempts included in this test script, one using curl and the other checking if the headers exist.
<?php
function url_exists($url) {
if (!$fp = curl_init($url)){
return false;
}else{
return true;
}
}
$url = 'http://24houredocs.com/enroll_updates/TEST_24houredocs_STANDARD_20140210.csv';
print"exists : ".url_exists($url);
$file_headers = @get_headers($url);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
print"<br>headers don't exist";
}else{
print"<br>headers do exist";
}
?>
The results print as
exists : 1
and
headers do exist
meaning the file exists and the headers exist...
But I can delete that .csv file from the folder and still get the same results.
So, what am I doing wrong?
Any ideas?