我有一個PHP腳本,它從遠程服務器獲取圖像,以便我可以使用HTML5畫布API處理它。file_get_contents在生產服務器上無法正常工作,可以在本地使用
<?php
if ((isset($_GET['url']))) {
$url = $_GET['url'];
$file_format = pathinfo($url, PATHINFO_EXTENSION);
try
{
header("Content-Type: image/$file_format");
header("Content-disposition: filename=image.$file_format");
$img = file_get_contents($url);
echo $img;
}
catch(Exception $e)
{
echo $e->getMessage();
}
}
else die('Unknown request');
?>
一個典型的要求是這樣的:
fetch_image.php?url=http://example.com/images/image.png
一切正常,我的本地服務器上,但在生產服務器上給我這個錯誤:
NetworkError: 500 Internal Server Error.
的錯誤日誌寄存器這消息:
PHP Warning: Cannot modify header information - headers already sent.
我已經嘗試了一些建議,但它不工作:
allow_url_fopen = 1
請粘貼完整的腳本(包括'<?php'標籤)。 – Dogbert
聽起來像一個錯誤的道路事 –
錯誤指向什麼行?請同時發佈確切的錯誤信息。 – Dogbert