Solved

Using Perl to Display Picture

Posted on 2006-11-29
7
206 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now