[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Showing a picture on a page

Posted on 2006-11-16
15
Medium Priority
?
179 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
  • 8
  • 6
14 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

873 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