View Full Version : Ways to read a file from an external host

08-01-2008, 04:46 AM
Problem: to read a file http://somesite.com/example.txt
I know a few ways to this but none would work for all circumstances.


$file = 'http://somesite.com/example.txt';
$source = file_get_contents($file);

It won't work on those hosts that allow_url_fopen not turn 'On'.


$file = 'http://somesite.com/example.txt';
system('wget ' .$file. ' > temp.txt');
$source = file_get_contents($temp.txt);

$file = 'http://somesite.com/example.txt';
system('curl ' .$file. ' > temp.txt');
$source = file_get_contents($temp.txt);

It won't work on those hosts that would not allow 'write permision' to a file.


$file = 'http://somesite.com/example.txt';
$ch = curl_init($file);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$source = curl_exec($ch);

This won't work on those hosts that have no cURL extension installed.

I run out of ways. Any hints would be appreciated. Thanks!

08-01-2008, 03:05 PM
Most webhosts I've used lately have "allow_url_fopen" disabled,
and they specifically give instructions on using cURL.

cURL is the preferred method.
If not available, then switch to a different webhost.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum