Bash / CGI - Premature end of script headers

Programming - Bourne / BASH

Issue

When trying to add a image to your CGI script you recieve the following error and the image isnt displayed.

[root@localhost cgi-bin]# cat /var/log/httpd/error_log
[Fri Jul 10 20:51:39 2009] [error] [client 10.2.2.5] Premature end of script headers: picture2.jpg, referer: http://10.2.2.1/cgi-bin/picture.cgi
[Fri Jul 10 20:57:57 2009] [error] [client 10.2.2.5] (8)Exec format error: exec of '/var/www/cgi-bin/picture2.jpg' failed, referer: http://10.2.2.1/cgi-bin/picture.sh

Solution

Add to your httpd.conf or apache.conf file an alias such as,

Alias /images/ /usr/share/images/

Once added restart you httpd/apache daemon. And add your images to the directory.

#!/bin/sh
unset PATH
echo "Content-type: text/html"
echo ""
echo "<html>"
echo    "<body>"
echo            "<img src="/images/picture.jpg">"
echo    "</body>"
echo "</html>"

 Your page should now display the picture.

Article updates via email..


We have 18 guests online