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.


function url_exists($url) {
  if (!$fp = curl_init($url)){
    return false;
    return true;

$url = '';

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";
    print"<br>headers do exist";

The results print as

exists : 1
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?

OK, found a cURL answer to the issue...

If this provides a $retcode of 200, then the file already exists, otherwise it doesn't...

Pretty simple, and it only took me 3 days to figure it out LOL
(actually I tried this a couple times before, but for some reason I thought that 400 meant it existed... Just totally confused myself.)

$ch = curl_init("");

curl_setopt($ch, CURLOPT_NOBODY, true);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// $retcode >= 400 -> not found, $retcode = 200, found.
  print"<br>Success - retcode is : ".$retcode."<br>";
  print"<br>FAILURE - retcode is : ".$retcode."<br>";

I'm going to make this Solved, because it is, but going to open a new question that I really need some help with, so stay tuned...