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

loop a file_get_contents until getting a non empty JSON in php

I have the following code:
R_life_R
  • 786
  • 6
  • 26
0
votes
1 answer

php emulate going to a webpage that constantly changes cookie

I have a webpage that I'd like to go to programmatically with PHP. I can go to that webpage "by hand" with chrome, right-click "inspect element" and find the cookie that is getting used when I visit the page. I then created a context with PHP…
rikkitikkitumbo
  • 954
  • 3
  • 17
  • 38
0
votes
1 answer

Load db.sql file into db using PDO

i use file_get_contents to get the queries from the file but now how can i load all of them into a mariadb database by using PDO? With mysqli i know there is a function called mysqli_multi_query is there another function that does the same but with…
Andrea
  • 134
  • 2
  • 12
0
votes
0 answers

php - Trying to download URLs from CSV, it stops at random URLs

I've tried searching for this issue but couldn't find out why it is actually failing at random stages. I have a CSV with 2 columns, ID and URL, there are 100 rows. I have the following code to loop through the CSV rows and use put_file_contents() to…
poncho
  • 1,100
  • 2
  • 15
  • 38
0
votes
2 answers

Php file_get_contents not capturing certain group of cookies

I have created a script to automate downloading a file created by an app that sends an email notice to the user when the file is generated. This script logs in, then executes a second time with some session items set on the host site and is able to…
0
votes
1 answer

php file_get_contents() works on test server but not on production server

I've my code in test server which uses file_get_contents() to get the status from a url. The test server link is: http://test1one.epizy.com/portal/test_api.php It works as it should and gives me the appropriate "Active" or "Inactive" response…
razn
  • 69
  • 3
  • 10
0
votes
3 answers

PHP file_exists With Contents Instead of Name?

Is there a function built into PHP that acts like file_exists, but given file contents instead of the file name? I need this because I have a site where people can upload an image. The image is stored in a file with a name determined by my program…
DMVerfurth
  • 172
  • 1
  • 13
0
votes
0 answers

How to convert a file_get_contents url with authentication to a cURL request

I have a script which gets some contents from a url using file_get_contents() $auth_headers = 'Authorization: Basic '.$api_credentials."\r\n". 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'."\r\n"; $auth_context…
Mann
  • 576
  • 1
  • 9
  • 33
0
votes
4 answers

read webpage (with dynamic content) and save

Im using file_get_contents() and the source is a url. Im also using ajax to insert html into the page. The page when loaded:
Zebra
  • 3,858
  • 9
  • 39
  • 52
0
votes
2 answers

PHP5 webpage scan (simple DOM parser || file_get_contents()+regexp)... resources wise

I was thinking about a script that would scan 10+ websites for specific content inside a specific div. Let's say it would be moderately used, some 400 searches a day. Which of the two in the title would support better the load, take less resources…
Michele
  • 3
  • 1
0
votes
1 answer

Request remote file with file_get_contents()

I need to query a page on another domain and display the results returned by it. But the php file reports an error. The url is: http://otherdomain/abc.jsp?p=q&x=y EDIT: I use file_get_contents...
ineedhelp
  • 125
  • 2
  • 9
0
votes
0 answers

how to get HTML/JSON from Instagram URL as a Browser in php?

As you know instagram Suspended his API,but for my app, i use below codes to get JSON of instagram page's posts: ini_set("allow_url_fopen", 1); $urlvars = urlencode('{"id":"'.$user_id.'","first":12,"after":"'.$end_cursor.'"}'); $url =…
saleh mosleh
  • 135
  • 1
  • 14
0
votes
1 answer

Passing User-Agent string with file_get_contents to Discogs API failing

Trying to retrieve some info from the Discogs API but I'm getting "Bad Request" every time I hit it programmatically. If I run the same url in the browser it works just fine, but as they require a User-Agent string to be specified in the request…
spice
  • 1,442
  • 19
  • 35
0
votes
1 answer

php file download works from browser but not cron job

I've looked on this site to see if anyone has this exact problem to no avail. I'm trying to download a URL using file_get_contents but while it works when I type the URL of the php script into my browser, the file is not obtained when I run the…
user3713442
  • 478
  • 8
  • 22
0
votes
1 answer

PHP: GET # of characters from a URL and then stop/exit?

For parsing large files on the internet, or just wanting to get the opengraph tags of a website, is there a way to GET a webpage's first 1000 characters and then to stop downloading anything else from the page? When a file is several megabytes, it…
Michael d
  • 305
  • 2
  • 16