Href for photo open in PHP - php

I have a photo gallery, after a click on the thumbnail I want to open image but not file but another php page with this certain photo and some other stuff, how can I give link attributes that php can use from the link?

When you ask something here, you need to explain more about your doubt and share some of the code. I don't know about the context but if you need to generate a link from an image to PHP file with parameters, you can send parameters GET and put the image in the link tag.
<a href="your_php_page.php?param1=something&param2=something">
<img border="0" alt="Description" src="thumbnail.jpg" width="100" height="100">
</a>
your_php_page.php
<?php
(isset($_GET['param1']))? $param1 = $_GET['param1'] : $param1 = null;
?>
More about GET parameters:
https://www.geeksforgeeks.org/how-to-get-parameters-from-a-url-string-in-php/
https://www.php.net/manual/en/reserved.variables.get.php

Related

Displaying image from different disk

Hi i want to show images from different disk.
Here is my code.
is it possible to do that ?
$a = "D:/img/1.jpg";
<img src="<?php echo $a; ?>" alt="...">
Im using this on my localhost.This is not for the web.
i add screenshot here.
when i come above the img it shows the link. but not show img. and i use lightbox.
but without lightbox its not show again.
example
The sample you provided/attached is only doable if you load the html file directly to your browser. It is not possible if you load it via localhost. In your case, you will have to do something like this:
<?php
$image = file_get_contents('D:/img/1.jpg');
$image_codes = base64_encode($image);
?>
<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />
Reference: How to retrieve and show images from another drive using src attribute in <img> tag?
I'd suppose to use such URLs with protocol: $a = 'file:///D:/img/1.jpg';

Php, How to pass address of a clicked image to another php file

is there any way in Php that when you click on a link, or an image, the address of that image would pass to another Php page so that I can use it ?
I have this code that I have a gallery, and when people click on one of the images in this gallery I want another page to be opened what the sub images of that project,
this is the general gallery view :
and when one of these images is clicked on, I need this page to be opened, note that each image on the main gallery has its own sub gallery.
I can do this in a complete static method, but I need to make it fully dynamic..
So summary of my question is that, Can i possibly pass the address of the images on the first gallery to the second gallery page so that I can pull out the images that are related to that gallery in the database?
thanks in advance.
You can pass the value in the link. Suffix your link with ?variable=value .
You can access it by $_GET['variable']
There are many ways to do this task.
One most popular way is pass image ID or Name through url like this
<img src="1234.jpg" />
Then use following code in your page.php to embed your image.
<?php $photoId = isset($_REQUEST['photoId']) ? $_REQUEST['photoId'] : null; ?>
<img src="<?php echo ($photoId != null) ? 'path/' . $photoId . '.jpg' : 'path/default.jpg'; ?>">
Why not give it a link? such as
<img src="xxx" />
Then in your page.php
$photoId = isset($_REQUEST['photoId']) ? $_REQUEST['photoId'] : null;

Open a fancybox gallery from another HTML file

I have two files, one with HTML code when I've diferent photo albums links, example:
<a href="albumprueba.php"><img class="fancyboxi"
src="Libro Fez/Libro Fez - 001.jpg" alt="image19"
width="91%" height="56" /></a>
And another file (is php) I've a routine that scans all the photos in a folder, and shows photos:
<a class="fancyboxi" data-fancybox-group="gallery" title="Laurea"
href="Libro Fez/<?php echo $archivos[$imagen_a_empezar]?>"><img
src="Libro Fez/<?php echo $archivos[$imagen_a_empezar]?>" alt="" width="19%"/></a>
I would like to open the HTML file from an album and open a fancybox with all the photos that showing the routine in PHP file.
I've tried to do in the HTML file this, but doesn't works:
<img src="Libro Fez/Libro Fez - 001.jpg" alt="image19" width="91%" height="56" />
Any idea? thank.
Your href is certainly malformed.
albumprueba.php?Libro Fez/Libro Fez - 001.jpg
That isn't an address as URLs cannot have spaces (go to it manually and check what the address is in the navigation bar in your browser). Moreover it's just landing on a jpeg - are you sure you want this link to be to a single image?
Other than that the anchor should work. Are you getting a 404 error after following the link? If you want the other html file to be perptually viewable from the parent page you should consider using an iframe.

Open image via url on another page inside a div with php

I have a link that recieves a dyanamic image via php, and when you click it, it opens the image in a new window. It looks like this:
Click Here
I want to open the image on a page called red.php, and inside a div with the id=green.
From the sending page I'm thinking of something like this:
Click Here
On red.php the code would possibly be something like this:
<?php
$picture = $_GET['IMAGE_FULL_URL'];
echo ".$picture"
?>
I'm sure I have something wrong above, and I don't know where to begin to add the div id to the url, or if I can simply place the php code inside the div. Can someone please show me the code so this will work? Thanks.
here is an example:
your initial HTML:
Click Here
your Red.php:
<div id="green">
<img src="<?php echo urldecode($_GET['pic']); ?>" alt="" />
</div>

Make active div for youtube URL a different shade

I have a page where in the top middle there is a large youtube player. Below it there are a bunch of youtube thumbnails which are clickable. Clicking them changes the player video to the thumbnail that was clicked. The youtube ID is passed thru the URL.
I wanted to change the shade of the thumbnail background so that the active ("clicked") thumbnail was shaded.
The following code generates the linked thumbnails:
while ($row = mysql_fetch_array($result)) {
$tubeID = $row['videoinfo'];
echo
'<div class="vid"><img src="http://img.youtube.com/vi/' . $tubeID . '/0.jpg" width="225" height="175"/></div>';
}
And the following code uses the clicked thumbnail to display the video:
<iframe id="player" width="640" height="385" src="http://www.youtube.com/embed/<?php echo $_GET['id'] ?>" frameborder="0"></iframe>
I know I need to compare the thumbnail URL to the current URL and if they match and set an ID to that thumbnail which can be assigned properties in CSS... though I'm not sure how to do so. Can someone help?
edit : this sorta explain what BZ suggested.
I kicked out some php to make the answer more concise. Don't forget to add it back.
<div class="vid">
<a href="videos.php?id=$tubeID" id="m+$tubeID" onclick="changeVid(this);return false;">
<img src="http://img.youtube.com/vi/01/0.jpg" width="225" height="175"/>
</a>
</div>
<script type="text/javascript>
function changeVid(obj) {
document.getElementById('player').src = "videos.php?id="+ substr(obj.id,1)
document.getElementById(obj.id).style.visibility='visible'; //or other style
document.getElementById(obj.id).setAttribute("class", newClass); //For Most Browsers
document.getElementById(obj.id).setAttribute("className", newClass); //For IE; harmless to other browsers.
}
</script>
of course, I'd be a lot easier with a JS framework... (ie jquery)
Basically, when you click a link, the function is called, when it's done, return false; disable the page loading (ignoring the href).
The function will change the iframe source and then will add some custom styling to the link you clicked to load the new video.
I've thrown a "m" in the link ID, because id can't start with numbers...
edit : my function changeVid lack some reset function to remove the old thumbnail active state (easy way to solve it : remove the active state from all thumbnail then put the active state on the clicked thumbnail.)
In each link you could put an onclick attribute to do some javascript that would do the highlighting.

Categories