2016-08-01 76 views
1

嘗試將圖像上傳到根目錄以通過url訪問它。在azure網站上存儲文件,但不能打開php

$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); 

當我打算在azure網站上訪問它時,它顯示一個空白頁面。 沒有顯示錯誤

+0

你有什麼更新? –

+0

yuup,謝謝它的工作 – user1837779

回答

1

隨着Azure的Web應用程序基於Windows的虛擬機,文件系統分隔符是\

請考慮下面的代碼片段:

header("Content-Type: image/jpeg"); 
$url = "http://my.com/myimage.jpg"; 
$dir = $_SERVER['DOCUMENT_ROOT'] . "\\"; 
echo file_get_contents($dir . basename($url)); 
0

你的腳本寫得正確。我曾嘗試和工作正常,但你需要設置圖像頭

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;