I have the code to dump pics in a directory and produce the result in a feed like instagram, i just want it to open the image onto a page with css and area for the picture already plotted out. I just need a jumping off point to open the images individually.
I hope this helps:
<?php
$dest = "index.php?id=" . SHOWPIC . "&path=" . $path;
?>
<a href="<?php echo $dest; ?>">
<img alt="Photo" src="<?php echo $path;?>">
</a>
SHOWPIC here is a constant that contains an integer. index.php should have something like:
if($_REQUEST["id"] == SHOWPIC)
require_once "showpic.php";
$path in my example is meant to contain the path to the image displayed.
showpic.php will then read the contents of $_REQUEST["path"] and display the pic. That's also the place where you can add CSS or whatever you like to the site.
Related
Not sure if this is even appropriate here, but I'm trying to work out how a banner rotator website is using standard html image code, to return a random banner?
<a target=_blank href=http://intellibanners.com/click.php?cid=campaign1>
<img border=0 src=http://intellibanners.com/campaign1.jpg>
</a>
In the example above, that html will display a random image from that campaign.
This started as a bit of a whim to see if I could set up something similar to work with different image sizes, but now it's driving me nuts... trying to figure out how to go from a image url to a database call to send back a different image!?
No lucky searching for ideas or examples, probably because I don't know what sort of processes or functions I should actually be looking for?
I'm thinking there must be some sort of url rewrite for all image calls, that redirects to a handler script...
That script makes the database call, grabs a random image from the nominated campaign, updates stats etc...
And possibly a php header response returns the corresponding image file?
But most of that is new to me and I'm not sure where/how to search for guidance or examples to get me started.
If anyone has any ideas on this, or even the kind of phrasing/functions I need that might help me get there in my own searching, it would be much appreciated!
(I've also installed and tested about 12 different rotator scripts hoping to find one that works the same, but no luck there either).
Thanks!
Matt
I wrote a php script that assumes to exist the wanted folders in the root of your website. Then you can invoke it in a simple way in any location of your website. Here is my script:
rotate.php
<?php
##########################################################
# Simple Script Random Images Rotator • 1.4 • 04.01.2020 #
# Alessandro Marinuzzi [alecos] • https://www.alecos.it/ #
##########################################################
function rotate($folder) {
if ((file_exists($_SERVER['DOCUMENT_ROOT'] . "/$folder")) && (is_dir($_SERVER['DOCUMENT_ROOT'] . "/$folder"))) {
$list = scandir($_SERVER['DOCUMENT_ROOT'] . "/$folder");
$fileList = array();
$img = '';
foreach ($list as $file) {
if ((file_exists($_SERVER['DOCUMENT_ROOT'] . "/$folder/$file")) && (is_file($_SERVER['DOCUMENT_ROOT'] . "/$folder/$file"))) {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if ($ext == 'gif' || $ext == 'jpeg' || $ext == 'jpg' || $ext == 'png') {
$fileList[] = $file;
}
}
}
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder . '/' . $fileList[$imageNumber];
}
return $img;
} else {
mkdir($_SERVER['DOCUMENT_ROOT'] . "/$folder", 0755, true);
}
}
?>
Now you can create a index.php file where you want and put this line:
<?php include("your_path/rotate.php"); ?>
<a target="_blank" href="http://intellibanners.com/click.php?cid=campaign1">
<img border="0" src="/<?php echo rotate('campaign1'); ?>">
</a>
other like this:
<a target="_blank" href="http://intellibanners.com/click.php?cid=campaign2">
<img border="0" src="/<?php echo rotate('campaign2'); ?>">
</a>
and so that...
You have only to create the wished folders in the root called campaign1, campaign2...etc...
then in each folder put the banner images of the current campaign...
for example: in the folder campaign1 put image like 001.png, 002,png, 003.png, 004.jpg, 005.jpg... (where these filenames match your campaign banners).
for example: in the folder campaign2 put image like 001.png, 002,png, 003.png, 004.jpg, 005.jpg, 006.gif, 007.png, 008.jpg... (where these filenames match your campaign banners).
Please note that if you don't want rename your banner images you can take the original names, my script will work in any way.
My script will turn all in wished output like this:
campaign1:
<a target="_blank" href="http://intellibanners.com/click.php?cid=campaign1">
<img border="0" src="/campaign1/002.jpg">
</a>
<a target="_blank" href="http://intellibanners.com/click.php?cid=campaign1">
<img border="0" src="/campaign1/007.jpg">
</a>
campaign2:
<a target="_blank" href="http://intellibanners.com/click.php?cid=campaign2">
<img border="0" src="/campaign2/004.png">
</a>
<a target="_blank" href="http://intellibanners.com/click.php?cid=campaign2">
<img border="0" src="/campaign2/005.gif">
</a>
See you and test all into your localhost website... for me works fine on PHP 7.4.5 and Apache 2.4.43.
The script will do the rest!
Hope this helps you!
I have a grid of thumbnails that when clicked on I want to load an overlay on the page showing the full size image and the contents of a text file as a caption.
Something like
<image src="thumbs/1001.jpg"> would just load the image, but I want to load the image in a light box sort of view and also load the contents to "desc/1001.txt" into a caption (not necessarily a <caption>) below the image.
I don't want it to reload the page if that can be avoided. If it helps, the images, thumbnails, and description all match the pattern above, or I also have a CSV file in the format of 1000,"Description of the picture" if that is simpler.
If you use something like https://lokeshdhakar.com/projects/lightbox2/#getting-started this should be fairly easy.
Your PHP code would look something like this:
<?php
$photos = [1000,1001];
foreach ($photos as $photo) {
$description = file_get_contents('desc/' . $photo . '.jpg');
echo '' . $photo . '';
}
?>
Using the code below with the Sphider search engine, Sphider will display an image in search results - if the html page and jpg share the same name (i.e) page14.html, and page14.jpg.
1) Without knowing the name of the image, how could the code be modified so that the first of 2-3 jpg's is displayed from the html page returned in search results ?
<?PHP
$url_path = "http://www.webpage.com/"; // The url to indexed pages.
$url_ext = ".html"; // The file ext. of indexed pages.
$image_path = "../"; // Path to image folder.
$image_ext = ".jpg"; // The file extension of images.
$image = str_replace("$url_path", "$image_path", $url);
$image = str_replace("$url_ext", "$image_ext", $image);
if (file_exists($image)) { // Do nothing
} else { $image = $image_path . "ICS" . $image_ext; } ?>
<img src="<?PHP print $image ?>" align="left" style="margin-right:10px;" />
Or,
2) How would I modify the above php code to display the images below in search results - without renaming all the images ?
I have many gallery pages with hundreds of the following html image links;
<img SRC="chair_0.jpg">
<img SRC="table_0.jpg">
<img SRC="bed_0.jpg">
In my case, all our webpage images have the same ID as the end of each page.
Following is an example of how our pages look like: www.mywebsite.com/category/sub-category/etc/details.php?category=6&subcategory=s&sc=180&productid=98
The pictures are located in another path, and share the same last digits (i.e 98) as web page.
Following is an example of picture folder: www.mywebsite.com/admin/picures/
In addition, all pictures have an extra "p" at the front and "_full" at end of the digits, as following example "p98_full.jpg", p109_full.jpg" or "p3_full.jpg".
Following method worked for me. You will need to past this on sphider/templates/standard/search_results.html line # 76, modify it a bit to match your setting and see if it works... (You do not need to add a url link to your site to this code, this should work as is)
<?PHP
$url_ext = ".php"; // The file extension of indexed pages.
$image_path = "../admin/pictures/"; // Path to image folder.
$pic_name = "p"; // Alphabet before image, if any.
$page_end = Substr ($url2, strrpos($url2, "=")+1); // Isolate digits or alphabets starting from end of page.
$image_ext = "_full.jpg"; // The file extension of images.
$image = $image_path . "$pic_name$page_end" . $image_ext; // Select isolated digits or alphabes.
if (file_exists($image)) { // Do nothing
} else { $image = $image_path . "ICS" . $image_ext; } ?>
<img src="<?PHP print $image ?>" alt="" align="left" style="margin-right:10px; border:0;" />
in php i want to ask how to get images one by one from folder directory and display in the jquery slider i have tried this php code by it's not working as i want?
<ul class="jcarousel-list">
<li class="jcarousel-item">
<?php
$directory = "data/uploads/topslider/";
if (glob($directory . "*") != false)
{
$filecount = count(glob($directory . "*"));
}
else
{
}
$files_index = glob("data/uploads/"."top"."slider/*.*");
for ($i=0; $i<$filecount; $i++)
{
$num2 = $files_index[$i];
?>
<img src="<?php echo $num2;?>" width="50" height="50" alt="" /> <?
}?></li>
</ul>
i want display like this:
Image1 Imag2 Image3......and So On from single folder or directory
There are four main things to check:
Is your $directory path correct relative to your current working directory in PHP? You can determine your current working directory by doing a temporary echo getcwd();. It needs to return the parent directory of your "data" folder for your code to work.
Is the data folder accessible from the current page on the web? e.g. if you manually remove the page from the URL (say, index.php) and add data/uploads/topslider/someimage.png where someimage.png is an image you know exists in your topslider folder, does the image load properly in the browser? If not, you'll need to update the way you build the src attribute in your img tag(s).
You're only adding one jcarousel-item for all your images, which doesn't seem right to me. I'm guessing you're expected to add a list item for each image.
You don't need to call glob twice just to ascertain how many files you have to work with. Just do a foreach statement once:
echo '<ul class="jcarousel-list">';
foreach(glob($directory . '*') as $filename) {
echo '<li class="jcarousel-item"><img src="'.$filename.'" width="50" height="50" alt="" /></li>';
}
echo '</ul>';
I hope this can be of great help to others, it took me awhile of PHP learning, but gave me a good PHP high when I pieced it together.
For those of you who are looking to put images next to your sphider results...
I use Sphider for indexing a product folder with thousands of items, here is an example of my file structure for use with this snippet:
www/
product/
item1.php
item2.php
item3.php
images/
item1.png
item2.png
item3.png
Insert this into sphider/templates/standard/search_results.html (or sphider/templates/dark/search_results.html) in line 75 just after " class="title">
<?PHP
// Edit here
$url_path = "http:// www.yoursite.com/product/"; // The url leading to your indexed pages.
$url_ext = ".php"; // The file extension of indexed pages.
$image_path = "../images/"; // Path to image folder.
$image_ext = ".png"; // The file extension of images.
// To here
$image = str_replace("$url_path", "$image_path", $url);
$image = str_replace("$url_ext", "$image_ext", $image);
if (file_exists($image)) {
// do nothing or Your Option
} else { $image = $image_path . "ICS" . $image_ext; } ?>
<img src="<?PHP print $image ?>" alt="" align="left" style="margin-right:10px; border:0;" />
Basically, if you have a page called 1234.php in your Sphider index, this will try to find picture 1234.png to go along side it of the search result. If an image is not found it will display a default image 'ICS.png' (Image Coming Soon).
Happy coding