Page 1 of 1

php - open new window with picture in it

Posted: Tue Jun 15, 2004 3:32 pm
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>";

Posted: Tue Jun 15, 2004 3:34 pm
by feyd
you'll have to use javascript.. search the forum for window.open

Posted: Tue Jun 15, 2004 3:45 pm
by ddragas
ok
but how to pas variable "$Slika7" to javascript?

$Slika7="something.jpg";

Posted: Tue Jun 15, 2004 3:48 pm
by dull1554
look in the code snippettes section of this forum
seek and ye shall find

Posted: Tue Jun 15, 2004 3:48 pm
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'')">
');

Posted: Tue Jun 15, 2004 3:52 pm
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.

Posted: Tue Jun 15, 2004 3:53 pm
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;

?>

Posted: Tue Jun 15, 2004 3:53 pm
by anjanesh
ddragas wrote:ok
but how to pas variable "$Slika7" to javascript?
$Slika7="something.jpg";
print ('<IMG SRC="'.$Slika7.'">');

Posted: Tue Jun 15, 2004 3:55 pm
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'')">
');

Posted: Tue Jun 15, 2004 4:39 pm
by ddragas
could this part of code "''some.com''" be my variable "$Slika7" with path of my picture taken from database?

Posted: Tue Jun 15, 2004 4:49 pm
by pickle
I believe so. That first variable is just the URL that is to be loaded in your newly opened window.

Posted: Wed Jun 16, 2004 4:47 am
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.

Posted: Wed Jun 16, 2004 9:39 am
by pickle
wrong spelling (width, height).

Posted: Wed Jun 16, 2004 12:13 pm
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?!?!?! :?

Posted: Wed Jun 16, 2004 1:15 pm
by ddragas
good point

thank you