Solved

Showing a picture on a page

Posted on 2006-11-16
15
170 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 500 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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