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
0 answers

PHP file_get_contents over network

I have XAMPP Server on Windows with IP Address : 192.168.184.215 Then I have Log Data Server on Windows with IP Address : 192.168.184.13 And now I'm running below PHP code(test.php) on browser from Log Data Server (call…
HiDayurie Dave
  • 1,791
  • 2
  • 17
  • 45
0
votes
0 answers

file_get_contents() Headera already sent

Ok guys I use this code for avoid hotlinking: ; ?> This code works just fine, and since I include it in all of my…
0
votes
2 answers

PHP file_get_contents problem

I am having a problem with PHP's file_get_contents command. $url = "http://api.rememberthemilk.com/services/rest/".$format.$auth_token.$filter."&api_sig=".$md5.$apikey.$method; $content = file_get_contents($url); $array = json_decode($content,…
01jayss
  • 1,400
  • 6
  • 19
  • 28
0
votes
1 answer

Failed to open stream with file_get_contents - can access it via endpoint in browser

I'm trying to use Coinbase's REST API to get a list of available currencies: Here is the endpoint - https://api.prime.coinbase.com/currencies You can see the JSON loads when you click the link above. $coinbase_coins =…
cpcdev
  • 1,130
  • 3
  • 18
  • 45
0
votes
1 answer

Manupulate Error file_get_contents

I have a script $data = file_get_contents('http://my_example_link/data.xml'); and if http://my_example_link/data.xml is showing error Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found I would like to create condition if the…
Gusti
  • 69
  • 3
  • 11
0
votes
1 answer

(php get content ) how can i use foreach loop to rid retrieving one string

I'm trying to get content of some table from url but it always gets one string. I was wondering if I could use foreach loop to get all strings which is in the table like:
Zabkas
  • 67
  • 9
0
votes
1 answer

Network error on downloading pdf file opened via file_get_contents() php

Can somebody please advice why the PDF is not downloading? Always it shows as network error when I hit download. The PDF file is 95 MB size, is that a reason for the network error? I am viwing the file using file_get_contents().
VishnuPrasad
  • 1,078
  • 5
  • 17
  • 36
0
votes
4 answers

get external script content as variable in php

I'm trying to get http://www.wowhead.com/spell=74217&power into a variable so that I can parse it as I like and save to my DB. I couldn't even get to echo it, I might be brain lagged though.
Weptile
  • 104
  • 2
  • 9
0
votes
0 answers

Can I use something like file_get_content in js?

I was making a website and I need to store output of a URL in a js variable..can I do that? I know I can use PHP for that purpose but I want to know is there any technique to store the output of a URL in a js varible??
Ganofins
  • 41
  • 2
  • 12
0
votes
1 answer

Variables not working inside file_get_contents php

Im trying to pull content from google maps API. But when I concatenate a variable inside the URL it doesn't work If I just use the plan text it works. What am i doing wrong here? Not working: $post_location = "lagos"; $url_loc =…
Tcmxc
  • 481
  • 1
  • 7
  • 23
0
votes
1 answer

Cookies are not being sent with file_get_contents or CURL requests

I am trying to send a file_get_contents request to a URL with POST data and a cookie set. My code is like that: $postdata = http_build_query( array( 'search' => 'test', 'token' => '0' ) ); // Create a stream $opts = array( …
Mario
  • 1,374
  • 6
  • 22
  • 48
0
votes
2 answers

file_get_contents - failed to open stream: HTTP request failed

I am getting the following error when I am trying to pass url values into "file_get_content"…
lStoilov
  • 1,256
  • 3
  • 14
  • 30
0
votes
3 answers

Function file_get_contents() returns false

I am using the function file_get_contents() in the script. But it is given false every time. $image_url = 'http://www.websitename.com/images/imagename.jpg'; $variable = file_get_contents($image_url); var_dump($variable); Its returning false I also…
Shashank Sharma
  • 585
  • 3
  • 14
0
votes
1 answer

How to displaying all data from all file_get_contents & search one of them

I have some txt files, and show only one file using the function file_get_contents (). if I want to find an object within each file, then I have to open the file one by one and search it using ctrl + f. I think it's not an effective way to search…
M Faisal Z
  • 13
  • 1
0
votes
1 answer

How can I get html from a specific node using DOMDocument()

I am using $doc = new DOMDocument(); I just want to get HTML from a particular id rather than the whole HTML. I tried $file=file_get_contents($url); $doc = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->formatOutput =…
Jasbir Rana
  • 259
  • 3
  • 13