Solved

Using Perl to Display Picture

Posted on 2006-11-29
7
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Logon script fails 23 61
Rename all files in a directory to numerical order 26 31
PowerShell logging 1 27
bulk create of subfolders in multiple parent folders 9 52
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…

749 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