file-get-contents

How can I download using PHP a XML file redirected in some weird way?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 21:58:31
问题 The file which I'm trying to download from my PHP script is this one: http://www.navarra.es/appsext/DescargarFichero/default.aspx?codigoAcceso=OpenData&fichero=Farmacias/Farmacias.xml But I can't do it using neither file_get_contents() nor cURL . I'm getting the error Object reference not set to an instance of an object. Any idea how to do it? Thanks a lot, Pablo. Updated to add the code: $url = "http://www.navarra.es/appsext/DescargarFichero/default.aspx?codigoAcceso=OpenData&fichero

file_get_contents() error

泪湿孤枕 提交于 2019-11-26 21:50:42
问题 I am using file_get_contents on my PHP and it throws some errors: My code #try to fetch from remote $this->remotePath = "http://some-hostname.com/blah/blah.xml $fileIn = @file_get_contents($this->remotePath); The errors: Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /virtual/path/to/file/outputFile.php on line 127 Warning: file_get_contents(https://some-host-name/data/inputFile.xml) [function.file-get-contents]: failed to

Need response body of HTTP 500 with file_get_contents (PHP)

我与影子孤独终老i 提交于 2019-11-26 21:45:50
问题 Using file_get_contents as part of custom SOAP implementation to apply SOAP calls (ALL libraries that we tried would not do SSL + certificate based authentication with SOAP 1.2 correctly). However difficult and barely-documented API often returns 500. There are error details in response body, but file_get_contents doesn't appear to allow access to it. fopen seems to have the same issue. What do? Prefer not to go to cURL due to heavy use of stream contexts to get authentication working. 回答1:

Ignoring errors in file_get_contents HTTP wrapper?

孤者浪人 提交于 2019-11-26 21:32:01
问题 The following code is to query an online thesaurus for a search engine I'm building as a college project, but I'm having problems with file_get_contents "failed to open stream" errors. When I send a word the thesaurus doesn't recognize, it throws up an error. I'm trying to write a piece of code that will ignore the error and just proceed without the information. $thesaurus_search="http://words.bighugelabs.com/api/2/0089388bb57f/".$this->formatted_query."/php"; $result_thesaurus=file_get

PHP file_get_contents ignoring timeout?

半腔热情 提交于 2019-11-26 21:31:47
问题 $url = 'http://a.url/i-know-is-down'; //ini_set('default_socket_timeout', 5); $ctx = stream_context_create(array( 'http' => array( 'timeout' => 5, 'ignore_errors' => true ) ) ); $start = microtime(true); $content = @file_get_contents($url, false, $ctx); $end = microtime(true); echo $end - $start, "\n"; the response I get is generally 21.232 segs, shouldn't be about five seconds??? Uncommenting the ini_set line don't help at all. 回答1: You are setting the read timeout with socket_create_context

file_get_contents - Special characters in URL - Special case

[亡魂溺海] 提交于 2019-11-26 18:37:07
问题 I'm not getting file_get_contents() to return the page in this particular case where the url contains an 'Ö' character. $url = "https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=CM_949A11_1534_1603_DAG_DST_50_ÖVRIGT_1_1&type=subgroup&startdate=20150101&enddate=20300501" print file_get_contents($url); How do I make file_get_contents() work as expected on this url? I have tried following solutions whithout a working result: 1. print rawurlencode(utf8_encode($url)); 2. print mb

Show image using file_get_contents

血红的双手。 提交于 2019-11-26 17:42:35
how can I display an image retrieved using file_get_contents in php? Do i need to modify the headers and just echo it or something? Thanks! Do i need to modify the headers and just echo it or something? exactly. Send a header("content-type: image/your_image_type"); and the data afterwards. robjmills You can use readfile and output the image headers which you can get from getimagesize like this: $remoteImage = "http://www.example.com/gifs/logo.gif"; $imginfo = getimagesize($remoteImage); header("Content-type: {$imginfo['mime']}"); readfile($remoteImage); The reason you should use readfile here

How to use CURL instead of file_get_contents?

不打扰是莪最后的温柔 提交于 2019-11-26 17:37:23
I use file_get_contents function to get and show external links on my specific page. In my local file everything is okay, but my server doesn't support the file_get_contents function, so I tried to use cURL with the below code: function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } echo file_get_contents_curl('http://google.com'); But it returns a blank page. What is wrong? try this: function file_get_contents_curl(

Upload a file using file_get_contents

不羁的心 提交于 2019-11-26 17:15:58
I realise I can do this with CURL very easily, but I was wondering if it was possible to use file_get_contents() with the http stream context to upload a file to a remote web server, and if so, how? First of all, the first rule of multipart Content-Type is to define a boundary that will be used as a delimiter between each part (because as the name says, it can have multiple parts). The boundary can be any string that is not contained in the content body . I will usually use a timestamp: define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true)); Once your boundary is defined,

How to get results from the Wikipedia API with PHP?

不羁岁月 提交于 2019-11-26 17:08:44
问题 I'm probably not supposed to use file_get_contents() What should I use? I'd like to keep it simple. Warning: file_get_contents(http://en.wikipedia.org/w/api.php?action=query&titles=Your_Highness&prop=revisions&rvprop=content&rvsection=0): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden 回答1: The problem you are running into here is related to the MW API's User-Agent policy - you must supply a User-Agent header, and that header must supply some means of contacting you. You