我有這個腳本輸出圖像到命令行,如果我將它重定向到file.png我可以正確看到圖形,但如果我嘗試從瀏覽器做同樣的事情,不要在飛行中看到它。PHP輸出到img標籤
我試圖將腳本分成兩部分,但不起作用。
1 - >生成圖表 2 - >從這一個調用第一個腳本並將所有腳本保存在一個變量中。
腳本:
<?php
header("Content-Type: image/png");
header("Content-Transfer-Encoding: binary");
ob_flush();
require_once ('/opt/rMON/config.php');
//if(isset($_GET['id'])){
// $id = trim($_GET['id']);
//} else {
// die("El id?");
//}
//DEBUG ID
$id=1;
$result = ***MYSQL QUERY***
$ip = long2ip($result['ip']);
$interface = $result['interface'];
$counter = $result['counter'];
$unix_name = $result['unix_name'];
$community = $result['community'];
$version = $result['version'];
$port = $result['port'];
$rrd_file = __RRD_ROOT__.$unix_name.".rrd";
$graph_name = $result['name'];
$host_ip = long2ip($result['ip']);
$iface_name = $result['iface_name'];
$fecha = date("y-m-d h:i:s");
$start = "3600";
$tiempo = "1 Hora";
create_graph($start, $graph_name, $fecha, $rrd_file, $input, $output, $host_ip, $iface_name, $tiempo);
function create_graph($start, $graph_name, $fecha, $rrd_file, $input, $output, $host_ip, $iface_name, $tiempo){
$opts = array (
"--imgformat=PNG",
"--slope-mode",
"--title=$graph_name ($host_ip) - $iface_name - $tiempo",
"--rigid",
"--base=1000",
"--height=120",
"--width=500",
"--alt-autoscale-max",
"--lower-limit=0",
"--font=TITLE:10:",
"--font=AXIS:8:",
"--font=LEGEND:8:",
"--font=UNIT:8:30:",
"--watermark=$fecha - Radu Radu",
"--start=-$start",
"--end=now",
"DEF:a=$rrd_file:$input:AVERAGE",
"DEF:b=$rrd_file:$output:AVERAGE",
"CDEF:cdefa=a,8,*",
"CDEF:cdefe=b,8,*",
"AREA:cdefa#00CF00FF:Entrante\t",
"GPRINT:cdefa:LAST:Actual\:%8.2lf %s",
"GPRINT:cdefa:AVERAGE:Promedio\:%8.2lf %s",
"GPRINT:cdefa:MAX:Máximo\:%8.2lf %s",
"LINE1:cdefe#002A97FF:Saliente\t",
"GPRINT:cdefe:LAST:Actual\:%8.2lf %s",
"GPRINT:cdefe:AVERAGE:Promedio\:%8.2lf %s",
"GPRINT:cdefe:MAX:Máximo\:%8.2lf %s"
);
$ret = rrd_graph("-", $opts);
if(!$ret){
echo "ERROR en el objeto: $graph_name ".rrd_error()."\n";
}
}
?>
我試圖輸出到PHP://輸出也沒有運氣。
正如我在日誌中看到的,輸出將轉到apache服務器日誌。
"dic 21 10:58:00 xxx.xxx.com httpd[27941]: [305B blob data]"
謝謝!
目前尚不清楚問題出在哪裏。檢查服務器在客戶端的響應:標題,內容。 – AlexM
你好,客戶端控制檯(谷歌瀏覽器)返回'資源解釋爲文檔,但與MIME類型圖像/ png傳遞:「https://test.xxx.com/graph.php」.' –
你能提供代碼,你已經用來顯示圖像(html) –