Saturday 15 August 2015

PHP open .txt file with full URL -


I want to read the content of a file with its full domain and the file path, something like this:

http://www.example.com/files/file.txt

What I can not do in this example:

.. / Files / file.txt

I have tried curl, fopen, file_get_contents and will not use the cue but it can not be found for any purpose.

Is there no reason why it is not working, which I am missing?

Here are code snippets for every effort, maybe someone knows what is wrong with one of them?

By coincidence, if I could do ../files/file.txt then it works for every option.

  $ file = "http: // www example.com/files/file.txt";   

Fopen:

  $ f = fopen ($ file, 'r'); $ Data = ''; While (! Feof ($ f)) $ data = Fread ($ f, $ size); Fclose ($ f);   

curl:

  function curl ($ url) {$ ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); $ Data = curl_xac ($ ch); Curl_close ($ ch); $ Return data; } $ Data = curl ($ file);   

file_get_contents: $ data = file_get_contents ($ file);

Thanks in advance for all help.

works fine for PHP 4 & gt; = URL with 4.3.0 and PHP 5:

"If enabled, then a URL with this function can be used as a filename"

Many shared hosters this option is disabled, or is using an earlier version of PHP and is loading external files using PHP.

Get started and take a look at your host web site so that it can block external files.

No comments:

Post a Comment