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.
#12

[eluser]bhakti.thakkar[/eluser]
it turned out to be something different. actually the file_exists() function looks out for a path something like var/www/applicationpath/upload files and i was passing http://IP_ADDERESS/applicationpath/upload file which is wrong.
i have rectified it and things are working fine now.
now i am declaring two paths
1. for file_exists() [var/www/etc etc]
2. for actual opening of the file via <a > [http://IP_ADDRESS/APPPATH etc etc]

Thanks for all the helps
#13

[eluser]TheFuzzy0ne[/eluser]
Glad you got it sorted.
#14

[eluser]bhakti.thakkar[/eluser]
Thanks but it unnecessary really took the hell out of me - Smile




Theme © iAndrew 2016 - Forum software by © MyBB