LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2014, 01:31 AM   #1
zama
Member
 
Registered: Mar 2012
Posts: 34

Rep: Reputation: Disabled
Image could not be loaded using CGI program


I am writing to write a cgi script to display a png image in a browser. When user clicks on the 'Submit' form in the HTML page , the CGI program is called to display the image .

But this is not working for me . When the script is executed , the text in alt section from img src HTML tag is displayed , rather than the image

The following is the snippet of CGI code.

!/bin/bash

echo "Content-type: text/html"

echo ""

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

echo "<img src="/home/zaman/graph/SSDGhistory.png" alt="DG-Reports">"
echo "</body>"
echo "</html>"

If I write the same code in plain HTML page , the PNG image is displayed fine.

Please suggest what I am missing in the code to display the image without any errors ?
 
Old 04-10-2014, 03:17 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Try View/Source in your browser to see what your script has done.
 
Old 04-10-2014, 09:32 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Shouldn't that be:

Code:
file:///home/zaman/graph/SSDGhistory.png
Quote:
If I write the same code in plain HTML page , the PNG image is displayed fine.
If you're comparing a CGI generated page that you loaded from a server, to a "plain HTML page" that you loaded from disk, then one big variable is how you loaded them. A page loaded from a server and a page loaded from disk do not behave in the same way.

Last edited by dugan; 04-10-2014 at 09:34 AM.
 
Old 04-10-2014, 09:40 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
For example, this line needs to be fixed:
Code:
echo "<img src="/home/zaman/graph/SSDGhistory.png" alt="DG-Reports">"
 
Old 04-10-2014, 01:57 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
the folder would be relative to what is set as "documentroot"
or
be accessible from the net with a ip address
 
Old 04-23-2014, 04:56 AM   #6
zama
Member
 
Registered: Mar 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by John VV View Post
the folder would be relative to what is set as "documentroot"
or
be accessible from the net with a ip address
Changing the path to something like http://path_known_to_webserver/SSDGhistory.png resolved the issue .
 
  


Reply

Tags
apache, bash scripting, cgi, html



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help me to decide correct fully loaded CD/DVD image of Debian 6 shivaa Debian 9 02-18-2013 01:05 AM
setting background image in cgi shell script rajib_145 Linux - General 1 05-18-2012 04:37 AM
background image for cgi file kaplan71 Programming 2 03-29-2008 07:20 AM
How to show image in CGI script? Barca Programming 2 07-23-2005 05:22 PM
C++ CGI Program(Tell Me what you think) karlan Programming 0 03-29-2004 01:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration