Jump to content

Recommended Posts

I have a simple page that takes url to images from MySQL and displays them, its basicaly something like:

<?php foreach($photos as $x) { ?>
<img src="<?php print($x['url']); ?>"> 
</img>
<?php } ?>

 

Now I want to add a link next to each photo so that when someone clicks on it it will take them to a new page with just thet one photo.

 

How can I do this?

Link to comment
https://forums.phpfreaks.com/topic/49453-solved-image-gallery/
Share on other sites

update for DaveEverFades code

<?php foreach($photos as $x) { ?>
<img src="<?php print($x['url']); ?>"> 
</img><a href="<?php print($x['url']); ?>" target='_blank' >Link text</a>
<?php } ?>

 

revised

 

<?php
foreach($photos as $x)
{
echo "<img src='{$x['url']}'></img><a href='{$x['url']}' target='_blank' >Link text</a>";
}
?>

 

 

EDIT: missed the _ ;)

Link to comment
https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242384
Share on other sites

here an easer way sorry but might have errors but your get the idear ok.

 

pictures.php


<?php foreach($photos as $x) { ?>

<?php echo"<a href='new_pic.php?cmd=".$x['url']." '>?>

<img src="<?php print($x['url']); ?>"> 

</img></a>";

<?php } ?>

 

 

new_pic.php

<?php
echo"<img src='".$_GET['cmd']."'> </img>";
?>

Link to comment
https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242386
Share on other sites

Sorry i done it to quick but here my version ok.

 

pic.php

<?php

//build an array off pictures and the folder exstention.

$pic=array("images/1.png","images/2.png","images/3.png");

// get the pictures from the array.

foreach($pic as $x){


// echo a link to a new page to show the picture the user press on.

echo"<center><a href='new_pic.php?cmd=".$x."'><img src='$x'></img></a><br><br></center>";
}

?>

 

 

place the img src tag anywere it needs to be displayed.

 

new_pic.php

<?php

// show picture from the url using the $_GET statement.
echo "<img src='".$_GET['cmd']."'>";

?>

Link to comment
https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242425
Share on other sites

Also this is kind off-topic, but I found a script that places a watermark on top of the picture:

<?php
// 'watermark' in the upper left of an image 
$my_text = 'watermark';

// open image and lay white text on it..
$img = imagecreatefromgif ('testpic.gif');
$white = imagecolorallocate($img, 255, 255, 255); // white
imagestring($img, 4, 6, 3, $my_text, $white); // size 4 built-in font

// send the image
//header("Content-type: image/jpeg");
imagegif($img);
imagedestroy($img);

?>

 

So what link should be used in the:

$img = imagecreatefromgif (????);

 

also how can I distinguish if it is a jpg, gif, png... ?

Link to comment
https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242436
Share on other sites

well firstly you it would be better if you have a folder with you images in and hold the image filename,

 

as for the script try this

 

image.php?image=doggy.jpg

<?php
// 'watermark' in the upper left of an image 
$my_text = 'watermark';

// open image and lay white text on it..
$img = imagecreatefromgif ('testpic.gif');
$white = imagecolorallocate($img, 255, 255, 255); // white
imagestring($img, 4, 6, 3, $my_text, $white); // size 4 built-in font

// send the image
header("Content-type: image/gif");
imagegif($img);
imagedestroy($img);

?>

 

change page2.php to image.php in my previous script,

 

to get the filetype you can just get the last 3 characters (won't work on renamed files ie test.gif to test.jpg)

 

for jpeg use imagecreatefromjpeg and imagejpeg

 

a switch to break them into groups would be best

Link to comment
https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242537
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.