Welcome Guest, Not a member yet? Register   Sign In
file exist check failing
#11

[eluser]TheFuzzy0ne[/eluser]
I am fully aware that the files are on a remote server. That's what the function checks... However, I've just noticed a missing 'l', which I've added in the original thread.

It will return FALSE if it gets a 404 from the server, TRUE if it gets 200 OK from the server. If the file doesn't exist on your server, it should return FALSE. If it keeps returning TRUE, it's very likely that you aren't giving it the correct URL.

Code:
function is_working_url($url)
{
    if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://')
    {
        $url = 'http://'.$url;
    }

    $header_arr = @get_headers($url);

    if (is_array($header_arr) && preg_grep('/HTTP\/\d+\.\d+ 200 OK/', $header_arr))
    {
        return TRUE;
    }
    
    return FALSE;
    
}
echo (is_working_url('google.com')) ? 'TRUE' : 'FALSE'; // Echoes TRUE.
echo '<br />';
echo (is_working_url('dfghgfhj.com')) ? 'TRUE' : 'FALSE'; // Echoes FALSE.

Whoops. I misread your post. If the files are local, then this function is no good for you. It's 4:32AM so I am off to bed now. If this isn't solved when I wake up, I'll see if I can help.


Messages In This Thread
file exist check failing - by El Forum - 02-23-2009, 04:13 AM
file exist check failing - by El Forum - 02-23-2009, 05:06 AM
file exist check failing - by El Forum - 02-23-2009, 05:16 AM
file exist check failing - by El Forum - 02-23-2009, 05:25 AM
file exist check failing - by El Forum - 02-23-2009, 05:28 AM
file exist check failing - by El Forum - 02-23-2009, 06:11 AM
file exist check failing - by El Forum - 02-23-2009, 06:17 AM
file exist check failing - by El Forum - 02-23-2009, 06:31 AM
file exist check failing - by El Forum - 02-23-2009, 07:00 AM
file exist check failing - by El Forum - 02-23-2009, 10:20 PM
file exist check failing - by El Forum - 02-23-2009, 10:35 PM
file exist check failing - by El Forum - 02-23-2009, 11:20 PM
file exist check failing - by El Forum - 02-24-2009, 05:36 AM
file exist check failing - by El Forum - 02-24-2009, 06:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB