开发者

URL exists gives "Does not Exists"

To check if url exists not regular file

Tried
1. file_exists - just a test, should not be for a url
2. empty
3. fopen

All the above gave a "Does not exists

if(fopen("http://www.google.com",r)){ echo "exists"; } else { echo "doesnot exist"; }

I have ran out of ideas as to why its happeni开发者_高级运维ng. the file has been given 777. Code is being tested from 127.0.0.1.

This is the only code on the page. I do not wish to use curl, and keep it simple and normal coding. Checked on Google and other Q's on stackoverflow

All I want to check is if the URL is real.


You need to enable allow_url_fopen in your php.ini config file.


Check your php.ini file and ensure you have access to the fopen function.

Also, the the first two parameters in fopen are strings. So the correct syntax of your command is:

if( fopen( "http://www.google.com", "r" ) !== false )


Maybe the php setting allow_url_fopen is set to false so this won't work. Did you try using CURL and checking the response headers?


I ran this at my local machine

if (fopen("http://www.google.nl", 'r')) {
    echo 'exists';
} else {
    echo 'no exists';
}

While you do have an error (r doesnt exist, but is interperted as 'r', unless you defined it elsewhere this shoudn't be a problem.

Check your local php configuration and or system configuration. (possible the ini setting allow_url_fopen)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜