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

How do I change the headers that PHP sends when using file_get_contents on an external URL?

I need to change the headers that PHP sends when it requests a file using file_get_contents(). Is that possible or would I have to use CURL?
Tom
  • 23
  • 2
0
votes
1 answer

How do use PHP file_get_contents or cURL with a log-in page that I'm already logged into

If I go to a website, example.com/page1.php, it is a log-in page. When I log-in, it takes me to example.com/page2.php. If I close my browser and come back to page1 later, I’m still logged in and it automatically takes me to page2. That means…
CheeseFlavored
  • 1,922
  • 1
  • 21
  • 28
0
votes
0 answers

Use file_get_contents in PHP Array to Update MySQL

I have a database contains ID and name of my Staff (DATABASE 1): -------------- | ID | name | -------------- | 1 | Mr.AA | | 2 | Mr.AB | |... | ... | | 78 | Mr.CZ | -------------- Then my colleague has the staff absence database per day for 2…
bakanoob
  • 21
  • 2
0
votes
1 answer

file_get_contents in php is not returning E-mail id, why?

Actually I am sending email from php. When I am using file_get_contents() for email body from external file, its not returning email id. Instead email id it's returning '[email protected]'. Here is my code to call the file with…
Manish Negi
  • 250
  • 4
  • 18
0
votes
2 answers

Why does php's file_get_contents incorrectly retrieve json files from xkcd?

In writing a PHP script to download xkcd comics, i incurred errors when trying to get specific comics (as opposed to the latest one). Specifically, pointing file_get_contents at the following url: xkcd.com/$COMIC_NUM/info.0.json inexplicably…
hally
  • 35
  • 1
  • 5
0
votes
2 answers

Is there a way to get round a 403 error with php file_get_contents?

I'm trying to get a specific webpage using php file_get_contents - when I view the page directly there is no problem but when trying to grab it using php I get "failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden". Theres a piece of…
user3713442
  • 478
  • 8
  • 22
0
votes
0 answers

file_get_contents returns an incorrect result if the content contains a sign "<" and a symbol after it

I have a file that contains something like this: first word
bva
  • 21
  • 1
0
votes
1 answer

Can't get json content from remote url

I've tried everything but still can't get JSON content from following url: http://onderbrekingen.infrax.be/onderbrekingen/Home/GetOnderbrekingen This is my lastest php: $url =…
phyck
  • 1
0
votes
3 answers

file_get_contents from remote client and SSL

I have PHP Laravel5 project. I use file_get_contents() in a controller's action like the following: $production = json_decode(file_get_contents(url('/operation/get-production/'.$job->id)))->production; The above route is excluded from…
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
0
votes
1 answer

PHP substr function does not parse properly in foreach

I have some files containing the similar formats as follows: Nearest Location: 771 km S 43° E of Quezon City 051 km S 66° E of Surigao City 007 km S 51° W of Socorro (Surigao Del Norte) 049 km N 70° E of PFZ EAST MINDANAO SEGMENT What I did was…
phiv
  • 23
  • 5
0
votes
0 answers

PHP file_get_contents not working with file onedrive (403 FORBIDDEN)

I have a web application with symfony 2.8 and i using Microsoft one drive to save my files. since December 2015 the function below work perfectly : public function indexAction(Request $request, File $file) { //RemotePAth :…
0
votes
2 answers

How to get file content with a proper utf-8 encoding using file_get_contents?

I need to get content of the remote file in utf-8 encoding. The file in in utf-8. When I display that file on screen, it has proper encoding: http://www.parfumeriafox.sk/source_file.html (notice the ň and č characters, for example, these are…
petiar
  • 1,047
  • 2
  • 14
  • 31
0
votes
0 answers

PHP - writing to a new line in a text file

First off, I would like to apologize if this is an amateur question, I am a student, and there is barely any tutoring available to me for these simple questions. EDIT: My issue was the microsoft notepad, as it is a linux server they can't agree on…
Bryant L
  • 21
  • 4
0
votes
1 answer

Appending PDF Files in PHP with Base64

I have a series of base64 PDF Files that I would like to merge together. Currently I am using file_get_contents() and with PHPMailer can attach each of them separately. $woFile = file_get_contents($url); $invoiceFile =…
Tino
  • 539
  • 2
  • 6
  • 18
0
votes
0 answers

file_get_contents works on localhost but not on server

I am trying to use the pokeapi.co api and it works fine when I make a file_get_contents request to it on my localhost, but when I put the same file onto my server, it does not work. Another api I have tested has worked and I have the allow_url_open…
1 2 3
99
100