[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Showing a picture on a page

Posted on 2006-11-16
15
Medium Priority
?
177 Views
Last Modified: 2008-03-06
Hello,

I have a Form which uses CGI and PHP. This Form uploads images to the production server and shows the url of uploaded images on the page (a working example is hier: http://www.eport.at/forms/forms.cgi?form=11).

Well, what I need is that: not the url of the uploaded image which currently this comment generates:
"Uploaded Files:<br/> $uploaded_files_html$ " 
but the image itself to be show on the page. My PHP knowledge is=0,  as HTML it should be: <img src="../../$uploaded_files_html$" >-
how can I write a PHP command for this purpose?
thanks

0
Comment
Question by:Shareece
[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
  • 8
  • 6
15 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17961718
You should be able to do it exactly the same way. ie
echo "<img src=\"../../$uploaded_files_html$\" >";

What happens when you do this?
0
 

Author Comment

by:Shareece
ID: 17961795
I updated the file on the server. It doesn't work. Maybe I have done something wrong? I changed the code like this:
Uploaded Files:
<br>

$uploaded_files_html$<br>
echo "<img src=\"../../$uploaded_files_html$\" >";

A brocken image symbol is been displayed :-(
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17961801
when you did view source how did it display?

the extra $ at the end may be confusing it
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Shareece
ID: 17961828
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17961842
ok, so what you are parsing is a html href code to your link.

What you will need to do is to split this with a regular expression - and then put it into an img src, will get back to you on that.
0
 

Author Comment

by:Shareece
ID: 17961861
I am confused :( Would you give me an example please?
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17961897
Hi,

I was confused what you actually had I thought you just had the location of the image,

what your value is;

<a href="http://www.eport.at/upload/8977447-84.jpg">http://www.eport.at/upload/8977447-84.jpg</a>

meaning that you need to strip the data between

<a href=" and ">

to get the address - and then put this through your img tags.

I'll tell you how to do it but  I'm not the best at using regular expressions (the best way to do this) and am busy at the moment - but will get back to you soon
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17963520
<?
      $matches= array();
      $pattern = "/((?<=href=')).*?(?=')/i";
      preg_match_all($pattern,str_replace("\"","'",$uploaded_files_html$),$matches);
        echo "<img src=\"{$matches[0]}\">";
?>
0
 

Author Comment

by:Shareece
ID: 17963736
Hello and thanks, unfortunately it still doesn't work. Maybe I have put the code on the wrong place. The whole code of the page is now like this:

<html>
<head>
<title>Test</title>
</head>
<body>
<form action="$cgiurl$" method=post>
<input type=hidden name="done" value=1>
<input type=hidden name="last_page" value="example_1_pg2">
$form_values$
<center>
<table width=450 cellpadding=4>
<tr><td colspan=2>
Uploaded Files:

$uploaded_files_html$<br>

<?
     $matches= array();
     $pattern = "/((?<=href=')).*?(?=')/i";
     preg_match_all($pattern,str_replace("\"","'",$uploaded_files_html$),$matches);
        echo "<img src=\"{$matches[0]}\">";
?>
</td></tr>
</table>

</form>
</body>
</html>

Thanks
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17969598
what does it return now with the source?
also - why do your values have a $ at the end of them?
0
 

Author Comment

by:Shareece
ID: 17969777
It shows exactly this screen as result:
Uploaded Files:
http://www.eport.at/upload/1610565-Test.jpg (this is an Url, which shows the image on a new page)
http://www.eport.at/upload/1610565-Test.jpg (This one not, just a text)

),$matches); echo "(hier a brocken image symbol)"; ?>

Maybe you will want to use the script online and see what happens: http://www.eport.at/forms/forms.cgi?form=11

Why a $ is been used? I don't know, this is a purchased script (form manager). For example if there is a text field with the name of "Address" on the first page, on the secound page stays $Address which retrives the value that has been entered for the Address on the first page.

Maybe some changes in admin.cgi are required. The part of the file admin.cgi that handels the images seems like this:
### Display Image

if($ENV{'QUERY_STRING'} =~ /.gif|.jpg^/gi) {$image = "$ENV{'QUERY_STRING'}"; &Display_Image; exit };
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17973970
Hi,

I'm confused how

$uploaded_files_html$<br> is actually echoing the result of your cgi - it appears that you are not calling php at all in this stage, so I would only expect $uploaded_files_html$ to display at that time.

additionally your system does not appear to support the short tags <? so


<html>
<head>
<title>Test</title>
</head>
<body>
<form action="$cgiurl$" method=post>
<input type=hidden name="done" value=1>
<input type=hidden name="last_page" value="example_1_pg2">
$form_values$
<center>
<table width=450 cellpadding=4>
<tr><td colspan=2>
Uploaded Files:

$uploaded_files_html$<br>

<?php
     $matches= array();
     $pattern = "/((?<=href=')).*?(?=')/i";
     preg_match_all($pattern,str_replace("\"","'",$uploaded_files_html$),$matches);
        echo "<img src=\"{$matches[0]}\">";
?>
</td></tr>
</table>

</form>
</body>
</html>


may work.

how do you normally get the values of your cgi into a variable?
0
 

Author Comment

by:Shareece
ID: 17974941
Unfortunately it didn't work again. The Script in already on the webserver. Once I click properties for the brocken image "http://www.eport.at/%22%7B$matches[0]%7D/%22" stays there. also %22 for the name of the image.

As I wrote my PHP knowledge is=0 and this is a purchased script for the contact forms with auto responder, more information is availble hier: http://www.cgi-world.com/form_manager.html. How it gets the values of cgi into a variabel, I have no idea.

Thanks, Sherry
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 2000 total points
ID: 17977553
What version of php are you using?

If you run the script

<?php
     $uploaded_files_html = "<a href=\"http://www.eport.at/upload/8977447-84.jpg\">http://www.eport.at/upload/8977447-84.jpg</a>";
     $matches= array();
     $pattern = "/((?<=href=')).*?(?=')/i";
     preg_match_all($pattern,str_replace("\"","'",$uploaded_files_html),$matches);
        echo "<img src=\"{$matches[0]}\">";
?>

Does it work?

It looks as though whatever you are doing it is actually processing your page before php is run over it, this is not normal.

If the above script as an independant page returns a link to the above jpg then it means that the script is working with your version of php - then we need to work out what your cgi script is doing.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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.
Suggested Courses

656 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