Reputation: 295
Trying to upload image into root directory to access it from url.
$url = "http://my.com/myimage.jpg";
$dir = $_SERVER['DOCUMENT_ROOT'] . "/";
var_dump($dir);
$ch = curl_init($url);
$fp = fopen($dir ."". basename($url), 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
When i'm tring to access it on azure website its showing a blank page. No error was displayed
Upvotes: 1
Views: 91
Reputation: 13918
As Azure Web Apps are based on Windows VMs, the file system separator is \
.
Please consider the following code snippet:
header("Content-Type: image/jpeg");
$url = "http://my.com/myimage.jpg";
$dir = $_SERVER['DOCUMENT_ROOT'] . "\\";
echo file_get_contents($dir . basename($url));
Upvotes: 1
Reputation: 153
Your script is correctly written. I have tried and works fine, but you need to set image headers
header("Content-Type: image/jpeg");
$url = 'http://my.com/myimage.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result= curl_exec($ch);
curl_close($ch) ;
echo $result;
Upvotes: 0