Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cgi/img prob

Status
Not open for further replies.

tommycahir1

Programmer
Feb 20, 2004
34
0
0
IE
hi all
i new to cgi and html and i am just trying to write a cgi script that shows an image to the screen.. the image is located in the same folder as the script but it aint appearing on screen .. the alt text is though..
shown below is the code that i have so far. this code is part of a much larger cgi script which will call this function to output the image mulitple times
print header;
print qq(<html>);
print qq(<head>);
print qq(<title>Results</title>);
print qq(</head>);
print qq(<body bgcolor = lemonchiffon>);
print qq(<CENTER><H1>Results</h1><CENTER><br><br>);
print qq(<h3><img src = "/A.jpg" alt = "should be pic ere"></h3>);
print qq(</body>);
print qq(</html>);
any help would be greatly appreciated..
tanx
tommy
 
Hello,

If your image is in the same directory as the script, then change:
print qq(<h3><img src = "/A.jpg" alt = "should be pic ere"></h3>);

to one of the following:

print qq(<h3><img src = "A.jpg" alt = "should be pic ere"></h3>);
print qq(<h3><img src = "./A.jpg" alt = "should be pic ere"></h3>);

What you have means to look for A.jpg in the root directory of your web server.

Hope this helps.
Phil
 
tried both of those with no luck i thought it mite be the way i was calling the img tag..
 
Not sure if this has anything to do with it, but...
Why do you have your image set inside <h3></h3> tags?
 
Are you hosting this on a unix box. If so, are you sure that the image in question is called "A.jpg" and not "a.jpg"?

The web server might also object to serving up images from the cgi-bin directory. That directory's really only for scripts - so the server might try to execute the jpg file instead of displaying it. I suggest you put the image file somewhere else, like this:
Code:
print qq(<h3><img src = "/images/A.jpg" alt = "should be pic ere"></h3>);


-- Chris Hunt
 
the <h3> tags dont affect it at all..

chris i created a folder with the name images and transfered the images there but still no luck..
 
you're writing out an image tag to the web page:

Code:
<h3><img src = "/A.jpg" alt = "should be pic ere"></h3>

you say the image is in the same directory as the script (e.g. [tt][ignore][/ignore][/tt])

You should position the image somewhere in the normal structure of the site (e.g. [tt][ignore][/ignore][/tt]) and write out the img tag to call it appropriately.

The image doesn't have to be in the same place as the script: it's not called by the script in any way, it's called by the user's browser.

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
If Manarth's post doesn't do it, then there's something wrong with the image. Did you upload it in binary mode?

There's always a better way. The fun is trying to find it!
 
Forgot this too: some FTP utilities will convert uppercase to lowercase - so your image may be A.jpg on YOUR pc but it could be a.jpg on the server. Just something else to check...

There's always a better way. The fun is trying to find it!
 
the following is an absolute path using the image tag and it still only produces the alt text u cant use the ip address outside the collage due to proxy and firewall.. the image was saved using binmode in perl..(binary mode)
the folder is setup and an alias is setup in the httpd.conf
using "ScriptAlias /images/ "/var/ "

print header;
print qq(<html>);
print qq(<head>);
print qq(<title>Results</title>);
print qq(</head>);
print qq(<body bgcolor = lemonchiffon>);
print qq(<CENTER><H1>Results</h1><CENTER><br><br>);
print qq(<h3><img SRC = " alt = "should be pic ere"></h3>);
print qq(</body>);
print qq(</html>);
 
What is the resultant HTML in the browser? Can you post it with [ignore]
Code:
...
[/ignore] tags around it?

I've noticed that you seem to have a space " " between the "SRC" and the "=" (and on the bgcolor attribute of the BODY tag) - have you pasted this from your source... it should be (without spaces before and after the "="):
Code:
print header;
        print qq(<html>);
        print qq(<head>);
        print qq(<title>Results</title>);
        print qq(</head>);
        print qq(<body bgcolor="lemonchiffon">);
        print qq(<center><H1>Results</h1><center><br><br>);
        print qq(<h3><img src="[URL unfurl="true"]http://149.153.130.5/images/image1.png"[/URL] alt="should be pic ere"></h3>);
        print qq(</body>);
        print qq(</html>);

Hope this helps.

Pete.


Web Developer &amp; Aptrix / Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Spaces around an = sign shouldn't matter in HTML, though you should try it without. What happens if you type


into the address line of your browser? Does it display the image? If (as I suspect) it doesn't, then the file's either not where you think it is or not called what you think it is. Either way, you need to look into how you FTP the files, or maybe how the web server's configured. If you do see the image, then there's something up with your script after all - though I can't find it!

-- Chris Hunt
 
when i type the address into the location bar it gives
"internal server error"
i'm working on the web server and the image is generated by the script and moved to the /images directory by the script.. so there no need to ftp

tanx for all your help folks
as chris says it prob a configuration error

if anybody can see a prob with the script alias below let me know i using apache 2.0..
<code>
ScriptAlias /images/ "/var/</code>
 
As per
The ScriptAlias directive tells Apache that a particular directory is set aside for CGI programs. Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client.

So, it's attempting to execute the images when they're requested, which isn't working. I bet your error logs would hint to this if you look at them. I think PaulTEG had one solution to this in your duplicate post in the CGI forum. And you could also try getting rid of the ScriptAlias and instead using a Directory with "Options +ExecCGI", which is also describe in the above link.
 
hi philote
tried paulTEG option and got rid of the scriptalias and now can view the images in my browser but still not through my script

chris
i can now see the image in the browser but not through my script all i see is the ugly little broken image box..
 
Just a general "DID YOU KNOW" reply. Some servers don't allow images to be accessed inside the cgi-bin, if the images and script reside in this directory or any directories below this, some servers will refuse you to load them in the browser.
 
yipee prob solved tanx for all the help lads it greatly appreciated

thanking you
tommy :)
 
actually didnt no that cgimonk
it one to note down for the future
tanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top