Short Tag – Web Development Blog

Entries Tagged ‘file_get_contents’

Stream Context in PHP (The CURL alternative)

In PHP there are several ways to get the content of a URL.
A well known method is using the function file_get_contents().
Another way would be using the cURL classes. The thing is, cURL may not be available an all hosts and you might be forced to use file_get_contents, or you just want to use file_get_contents() because [...]

Force browser to download file (not open): jpg, pdf, mp3, etc.

So, you know that modern browsers open media files (and others). For example if you have installed Quicktime then most of the browsers will open mp3 files instead of downloading them, every browser will open image files(jpg, gif, png) instead of downloading them. If you want to force the browser to download the specified files [...]

file_get_contents() timeout in PHP

Though file_get_contents is not so advanced as CURL we can use it in lots of situations. In case you use file_get_contents and you need to set for how long to try to make connection you can use stream context.
First we create the stream context:
$sc = stream_context_create(array( ‘http’ => array( [...]