Need help with file_get_contents - curl

software development

#1

Hi,

i have just signed up on dreamhost and moved my site… But ive heard that dreamhost has disabled file_get_contents function that i was using… On the wiki pages, i saw an alternative called as “cUrl” but i cant understand it and couldnt make it work… Could you please help me changing that code to work on dreamhost?


if ($action == ‘image’) { $rmtimage = $_POST[‘rmtimage’];
$imgget = file_get_contents("$rmtimage");
$filename = strtolower(basename($rmtimage));
file_put_contents2("…/images/upload/$filename", $imgget); }

elseif ($action == ‘game’) { $rmtswf = $_POST[‘rmtswf’];
$swfget = file_get_contents("$rmtswf");
$filename = strtolower(basename($rmtswf));
file_put_contents2("…/swf/upload/$filename", $swfget); }

else { echo “

Sittiir! Çalýþmadý!

”; }

Thanks & Have a nice day

Burak


#2

You could use this:

if ($action == 'image') { $rmtimage = $_POST['rmtimage']; $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, $rmtimage); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $imgget = curl_exec($ch); curl_close($ch); $filename = strtolower(basename($rmtimage)); file_put_contents2("../images/upload/$filename", $imgget); } elseif ($action == 'game') { $rmtswf = $_POST['rmtswf']; $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, $rmtswf); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $swfget = curl_exec($ch); curl_close($ch); $filename = strtolower(basename($rmtswf)); file_put_contents2("../swf/upload/$filename", $swfget); } else { echo "<h1>Sittiir! Çalýþmadý!</h1>"; }or even better, because it hides the cURL stuff in a function…

[code]// function to replace file_get_contents()
function file_get_the_contents($url) {
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}

// original script updated with new function
if ($action == ‘image’) {
$rmtimage = $_POST[‘rmtimage’];
$imgget = file_get_the_contents($rmtimage);
$filename = strtolower(basename($rmtimage));
file_put_contents2("…/images/upload/$filename", $imgget);
} elseif ($action == ‘game’) {
$rmtswf = $_POST[‘rmtswf’];
$swfget = file_get_the_contents($rmtswf);
$filename = strtolower(basename($rmtswf));
file_put_contents2("…/swf/upload/$filename", $swfget);
} else {
echo “

Sittiir! Çalýþmadý!

”;
}[/code]--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]

#3

Thank you very much!! It does work :slight_smile: