Apache 通过CGI程序加载PNG图像失败,出现错误

Apache 通过CGI程序加载PNG图像失败,出现错误,apache,bash,html,cgi,Apache,Bash,Html,Cgi,我写这篇文章是为了写一个cgi脚本,在浏览器中显示png图像。当用户单击HTML页面中的“提交”表单时,会调用CGI程序来显示图像 但这对我不起作用。脚本试图在浏览器中打开PNG图像,但该图像包含以下错误消息 "The image “http://localhost/cgi-bin/image.sh?subbtn=Submit” cannot be displayed, because it contains errors." 下面是CGI代码的片段 !/bin/bash echo "Co

我写这篇文章是为了写一个cgi脚本,在浏览器中显示png图像。当用户单击HTML页面中的“提交”表单时,会调用CGI程序来显示图像

但这对我不起作用。脚本试图在浏览器中打开PNG图像,但该图像包含以下错误消息

"The image “http://localhost/cgi-bin/image.sh?subbtn=Submit” cannot be  displayed, because it contains errors."
下面是CGI代码的片段

!/bin/bash

echo "Content-type: text/html"
echo "Content-type: image/png"

echo ""

echo  "<html>"
echo "<body>"
echo "Hi"

echo "<img src="/home/zaman/ssdggraph/SSDGhistory.png" alt="DG-Reports">"
echo "</body>"
echo "</html>"
另外,如果我在纯HTML页面中编写相同的代码,PNG图像显示良好


请说明我在代码中缺少了什么,以便在没有任何错误的情况下显示图像?

您应该为可以从浏览器访问的
属性指定URL

/home/zaman/ssdgraph/SSDGhistory.png
不太可能满足该要求。(您可能应该有类似
http://path_known_to_webserver/SSDGhistory.png


您可能还应该阅读web页面和cgi脚本的概念。我会把一个CGI称为“显示图像”,这个程序会在上面的URL中被引用,一旦网页引用它,浏览器请求它,它就会动态地输出图像数据。这可能是您的意思,但有点不清楚。

您必须使用内容类型,然后使用空行:

#!/bin/bash
echo "Content-type: image/png"
echo
cat /var/www/img/your-image.png

这似乎是一个编程问题,建议移到SO.relative路径,您的Web服务器无法访问file@ChrisDown我发现这是一个Web服务器问题这里没有任何东西表明这只是一个编程错误。已将映像复制到Web服务器的DocumentRoot,但仍然无法加载映像
#!/bin/bash
echo "Content-type: image/png"
echo
cat /var/www/img/your-image.png