Solved

Showing a picture on a page

Posted on 2006-11-16
15
168 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
Comment Utility
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
Comment Utility
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
Comment Utility
when you did view source how did it display?

the extra $ at the end may be confusing it
0
 

Author Comment

by:Shareece
Comment Utility
0
 
LVL 35

Expert Comment

by:Raynard7
Comment Utility
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
Comment Utility
I am confused :( Would you give me an example please?
0
 
LVL 35

Expert Comment

by:Raynard7
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 35

Expert Comment

by:Raynard7
Comment Utility
<?
      $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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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