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

How to access the file in another folder file_get_contents()

This file is runing my-site.com/includes/classes/build/cg.php and it loads my-site.com/data/data.json with a such structure $data = json_decode(file_get_contents("http://my-site.com/data/data.json"), true); I want to load it with relevant path,…
Rast Wishes
  • 59
  • 1
  • 12
0
votes
1 answer

Not able to read cookies file that saved by CURL

I'm not able to read cookies file that saved by CURL
user2203703
  • 1,955
  • 4
  • 22
  • 36
0
votes
0 answers

Multiple requests calling file_get_contents results in error 500 "failed to open stream: HTTP request failed!"

I'm developing a REST API with Laravel as the backend of my app. The frontend is made with React/Redux. The server is a Windows IIS machine. I'm having a problem submiting a list of attachments to a model. The upload process from the frontend is the…
0
votes
2 answers

cURL and file_get_contents not working for specific URL

I use cURL / file_get_contents very often to get a page's source code. However, there is one website where this is not working for me. Here is the code:
MantiNL
  • 69
  • 12
0
votes
1 answer

PHP timeout doing multiple curl and filegets

I have a php script that does a get request to an api, and with the results has to fetch over 1000 images. My problem is that in the process of doing this I always get a timeout. What should be my best approach for this? I've tried to do a loop with…
0
votes
0 answers

better and faster way to display a remote image: src = "http://URI_IMAGE", base64 of file_get_contents() or base64 of cURL using php

I need a clearing please, I would like to know the most efficient and fastest way to display an image in a html page. runs between loading the remote image by downloading with file_get_contents and then converting to base64, or downloading with cURL…
kevin kemta
  • 90
  • 10
0
votes
3 answers

Get value of Attribute using file_get_contents

i want to the value of the attribute href from a specific link. the html code where i want to fetch the value looks like this: Some link i want to have the inner href (mailto:mail@xy.com) but i get the value of the…
LovinQuaQua
  • 111
  • 2
  • 12
0
votes
1 answer

file_get_contents() works differently on different machines

I have written a piece of php code to use file_get_contents() to download a .js file from a site and try to run the code from 2 different machines and they produce different results. The code is: $link =…
albertma789
  • 353
  • 2
  • 3
  • 11
0
votes
1 answer

How to bypass JavaScript redirection by getting content through PHP GET/POST

I try to collect domme information (NOTAM) on this form through PHP. The problem is, the website uses JavaScript redirection to process the POST request 2 times (on link 1 then on the form address (using POST), then redirects the user to form…
Bernard Rosset
  • 4,523
  • 6
  • 27
  • 29
0
votes
0 answers

Failing to load a JSON File on my server

first of all, my script: ' . print_r($json, true) . ''; ?> I am not aloud to share the link but it is a json file, which is ip protected.…
sindbad
  • 1
  • 1
0
votes
0 answers

Getting error Network is unreachable for File_get_contents

I have been using file get contents to get the content of following site however i am getting the following error can anyone explain why so? file_get_contents("https://www.watchserieshd.co"): failed to open stream: Network is unreachable Also i…
Adarsh Chouhan
  • 11
  • 1
  • 1
  • 6
0
votes
2 answers

Using file_get_contents with basic auth and SSL

I'm attempting a GET request using SSL and basic auth using the file_get_contents function: $username = "XXXXXXXXXX"; $password = "XXXXXXXXXX"; $url =…
David Jones
  • 10,117
  • 28
  • 91
  • 139
0
votes
0 answers

post json with file_get_contents

before trying to create the script, I tried first using the postman application, and all went smoothly without any constraint, but after I use the script I have made, the result is not the same as given by the application postman. this is the result…
Ronald J
  • 1
  • 3
0
votes
2 answers

how to prevent php function file_get_contents to truncate my request

I use file_get_contents to send a request to a web service, let say: https://example.com/mywebservice?arg1=value1&arg2=value2 If value2 is avaluewith#sometextafter, I…
Eric Malalel
  • 185
  • 1
  • 17
0
votes
1 answer

Check file_get_contents close because of timeout

I have a script to download image from China server, so image might not be able to download correctly like only partial image shown because of CDN. Guess because of timeout? Any ways to check image is not downloaded completely? $content would not…
Pak Ho Cheung
  • 1,382
  • 6
  • 22
  • 52