Solved

Using Perl to Display Picture

Posted on 2006-11-29
7
210 Views
Last Modified: 2013-12-25
my directory structure is /home/p/public_html/cgi-bin/
I am trying to display a pic (using perl)outside of public_html ... I tried doing      

header ('image/gif');
print "<IMG SRC=\"/home/p/pic.gif\">";

but when i render it i realise it is looking for the picture  at www.servername.com/home/p/pic.gif 
and i guess since it doesn't have permission for /home/p it just diplays the red x.  

How can i solve this problem?

Thanks
0
Comment
Question by:nebest
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 18040604
Yes, public_html is normally set up for everyone to read. You could grant read access to all on the diretory /home/p
Your HTML may also be set up to define a base reference point of /home/p/public_html
0
 
LVL 48

Accepted Solution

by:
Tintin earned 125 total points
ID: 18040870
You need to do

#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;
print $q->header('image/gif');
open IMG, "/home/p/pic.gif" or die "Can not open pic.gif $!\n";
binmode IMG
print <IMG>;
close IMG;
0
 

Author Comment

by:nebest
ID: 18041085

I tried using the suggestion by Tintin and I get a bunch of garbled text printed to screen ... what do i need to do to convert it to an actual image.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 48

Expert Comment

by:Tintin
ID: 18041532
What browser are you using?  Have you opened the image directly in the browser previously?
0
 

Author Comment

by:nebest
ID: 18041580
I am using internet explorer.  I can open the image perfectly directly when its in public_html.  I know its reading the image file, can you give me an idea why i would see garbled data rather than pic. is there some header i may not be including?
0
 

Author Comment

by:nebest
ID: 18041622
The code you sent works perfectly, thank you... I guess it has something to do with the fact that I am also printing text  data in the same perl script.  I just tried using your code without any other code and it works.  

Thanks for your help
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18041685
You can't mix content types (as you found out).
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I do this in Pyhton? 12 131
Python variable _ manually assigned 9 90
ROBOFTP UNZIP 1 53
Transform normalized CSV to line in powershell 7 46
Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question