[SOLVED] php - open new window with picture in it

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

php - open new window with picture in it

Post by ddragas »

How to open new window (with php) without toolbar, statusbar, standard buttons, address bar, links, (in one word - without anything), but with picture in it.


$Slika7="something.jpg";

echo "<img src="'. $Slika7 .'" border="0"></a>";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'll have to use javascript.. search the forum for window.open
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

ok
but how to pas variable "$Slika7" to javascript?

$Slika7="something.jpg";
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

look in the code snippettes section of this forum
seek and ye shall find
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

print ('
<IMG SRC="s.jpg" onclick="javascript:window.open(''some.com'', WindowName,''menubar=no, resizable=no,scrollbars=no, status=no, titlebar=no, toolbar=no'')">
');
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

anjanesh wrote:print ('
<IMG SRC="s.jpg" onclick="javascript:window.open(''some.com'', WindowName,''menubar=no, resizable=no,scrollbars=no, status=no, titlebar=no, toolbar=no'')">
');
WindowName needs to be a string, without spaces and several other special characters.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If, for example, you want to open image_y.jpg in a window, via a user-click, you would have to put "image_y.jpg" in the URL of the link, or somehow pass it to the new page.

So, if your HTML was like this:

Code: Select all

&lt;a href = "javascript:open_image_window('image_y.jpg');"&gt;
&lt;img src = "image_y_thumb.jpg"&gt;
&lt;/a&gt;
your javascript would be like this:

Code: Select all

function open_image_window(image_name)
&#123;
  window.open('single_image_view.php?image=' + image_name','newWindow',features);
&#125;
(the variable "features" is a string that sets properties of the window. Do a google search on [google]Javascript: window.open[/google] to find out about that.)

Then, in your PHP page,

Code: Select all

<?PHP
$image_to_display=$_GET['image'];
echo <<<IMAGE
<img src = "$image_to_display">
IMAGE;

?>
Last edited by pickle on Tue Jun 15, 2004 3:58 pm, edited 2 times in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

ddragas wrote:ok
but how to pas variable "$Slika7" to javascript?
$Slika7="something.jpg";
print ('<IMG SRC="'.$Slika7.'">');
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

print ('
<IMG SRC="s.jpg" onclick="javascript:window.open(''some.com'', ''WindowName'',''menubar=no, resizable=no,scrollbars=no, status=no, titlebar=no, toolbar=no'')">
');
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

could this part of code "''some.com''" be my variable "$Slika7" with path of my picture taken from database?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I believe so. That first variable is just the URL that is to be loaded in your newly opened window.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

I've resolved problem in this way.

This is first page.

<?
$slika= "slike/zaglavlje/reljef_1.gif";
$img_src1="slike/strana/5star.gif";

print ('
<IMG SRC="' . $img_src1 . '" onclick="javascript:window.open(''veliki_tumbnail.php?slika='.urlencode($slika).''', ''WindowName'',''menubar=no, scrollbars=no, status=no, widith=150, hight=600, resizable=no, titlebar=no, toolbar=no'')"> ');

?>


And code in second page called "'veliki_tumbnail.php" is


<?
echo '<img src="'. $slika .'" border="-1"></a>';
?>



My question is why page is not opening in
widith=150, hight=600 like I wanna.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

wrong spelling (width, height).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
choppsta
Forum Contributor
Posts: 114
Joined: Thu Jul 03, 2003 11:11 am

Post by choppsta »

It always concerns me when I see file paths being sent via the querystring and then just plonked in...

In this case it probably wouldn't be much of an issue as it's an image that's being output.

If I need to pass a file name I usually don't include the path or extension (as these are usually known by the script) and then do this to it:

Code: Select all

<?php
$filename = preg_replace("/\W/", "", $filename);
$path = '/blah/blah/'.$filename.'.ext';
?>
This strips out any nonword characters (but leaves underscores).

Is it just me that does this kind of thing, am I being TOO paranoid?!?!?! :?
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

good point

thank you
Post Reply