Questions tagged [file-get-contents]

In PHP, file_get_contents is the preferred way to read the contents of a file into a string. It will use memory mapping techniques (if supported by your OS) to enhance performance.

In PHP, file_get_contents is used to read an entire file into a single string. Depending on the server configuration, it can also be used to read URLs as well. It differs from file(), in that file is designed to return a resource pointer and then used read the file in chunks (i.e. CSV files). Use file for large files that should not be read all at once. Use file_get_contents to read smaller files and files that cannot be read as easily read in chunks (i.e. JSON)

For more details see the PHP manual entry.

2607 questions
0
votes
1 answer

file_get_contents with Variable

Hey so I'm having a slight dilemma with getting the contents of a file using a variable. So to explain the code below a little, the respform fetches JSON array all ok. And the results url when echo'd displays like a normal URL that when viewed…
Jack Ellis
  • 29
  • 1
  • 1
  • 6
0
votes
0 answers

How to make many requests with CURL without using the full CPU?

I'm sending about 300 messages using an api using CURL requests with a for loop , It's working but takes the whole CPU. Here is the code : //Initializing CURL. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "websiteURL"); curl_setopt($ch,…
user9544660
0
votes
1 answer

php: file_get_contents() works for every external website, but doesn't work for page on same host

Server has nginx and php on it. When i am trying to echo file_get_contents(); with any website as input - everything works fine when i am trying to echo file_get_contents(); with url of page which is on the same server - timeout shows up. I tried…
Sid
  • 4,302
  • 3
  • 26
  • 27
0
votes
0 answers

Retrieve file from temp on live server

I have a file stored in temp folder. In localhost, when I run the following function: $return_res = $documentRetrieved->getPathname(); I get back: C:\Windows\Temp\A2C2.tmp While in live server with the same code, I get: /tmp/cdbQpa When i run…
CloudSeph
  • 863
  • 4
  • 15
  • 36
0
votes
1 answer

Display external html specific value

I want to display the "hiOutsideTemp" value from this html page: http://amira.meteokrites.gr/ZWNTANA.htm to my page. It's a temp value. I'm using the following code:
koukou
  • 13
  • 1
  • 5
0
votes
0 answers

GC Variable not working in PowerShell: it doesn't return any results

I've got a .txt file that I'm trying to get-content from, and I'm struggling to turn the gc into a variable... I'm running: $variablesfile = gc .\Variables.txt I've also put the entire filepath here instead of just .\Variables.txt, and I know I'm…
Christopher Cass
  • 817
  • 4
  • 19
  • 31
0
votes
1 answer

PHP fetching data from URL

I'm having problems with fetching data from URL. When I input URL in browser file normally gets downloaded to my computer, but when I try to access it in my code I get response FALSE, with no errors just bool(false) response. It's function for ICAL…
0
votes
1 answer

Secretly adding (extra) HTTP GET Variables to a swf file through PHP

I'm trying to build a workaround for embedding my (downloaded) flash videoplayer. (it's the JWplayer...) At the moment, when somebody wants to embed the videoplayer they have to include the swf with all the added flashvars (ex:…
0
votes
0 answers

html file_get_contents() encoding issue

I try to display html content file into php. $file_to_load = "index.html"; $html_page = file_get_contents($file_to_load); But it's output : �<�!�D�O�C�T�Y�P�E� �h�t�m�l�>���<�h�t�m�l�>�� And mb_convert_encoding($html_page , 'UTF-8' ,…
0
votes
2 answers

Get full content of uploaded XML file in PHP

I'm building a file upload form where users can submit XML configuration files. My goal is to get the full contents and insert them into Wordpress as a new post (custom post type). It's working for the most part, except I am having difficulty…
Aidan Knight
  • 253
  • 2
  • 11
0
votes
1 answer

Recieve Variable From php file Using fopen?

I've been working on a blogging system and I wish to receive information from external php files for a post's Title and Content, here is my code: External (Blog Post's Content) File: 03-20-2018-This-Is-A-Test.php
Nathan Martin
  • 295
  • 1
  • 3
  • 13
0
votes
1 answer

cURL / PHP cant fetch this - but all browser can?

I cant acces this site with any of Bellow methods, the $url adress Works in all my browsers but, i just cant fetch data from that site.... how is that possible ? Not even the robots.txt ('https://www.natterer-modellbau.de/robots.txt) cant be…
0
votes
3 answers

Browser loads the page but CURL/file_get_contents redirects

I use this page to get the current currency conversion: http://finance.google.co.uk/finance/converter?a=1&from=EUR&to=GBP It has worked okay for over a year using file_get_contents but all of a sudden it stopped working. I then tried curl and it is…
Dan
  • 103
  • 1
  • 13
0
votes
1 answer

file_get_html & str_get_html with cURL are getting part of a page

This is a really weird situation that I can't explain. I use simple HTML DOM and am trying to get the full code of this page: http://ronilocks.com/ The thing is, I'm getting only part of what's actually on the page. For instance: look at the page…
Avi
  • 728
  • 3
  • 10
  • 20
0
votes
0 answers

Failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request Apache

I am trying to use IP address to get file_get_contents $url = "http://82.33.33.100:8001"; // Ip address, it example IP address. ( not correct ip address here) $data =file_get_contents($url); I am getting following error: failed to open…
Ankita Kashyap
  • 517
  • 6
  • 20