PHP - Display Images In Order Created
I have the following code which displays images and captions from a directory. I would like the images to be displayed in the order they were created. Somebody suggested I use glob(), but I have no idea how.
<?php $dir = "exclusive_images/"; if ($opendir = opendir($dir)) { //read directory while(($file = readdir($opendir)) !==FALSE) { if ( file_exists($dir.'/'.$file) && in_array( strtolower(pathinfo($file,PATHINFO_EXTENSION )), array('png','jpg','jpeg','gif'))) { if (file_exists($dir.'/'.$file. '.txt')) $caption = file_get_contents($dir.'/'.$file. '.txt'); else $caption = ucwords(str_replace(array('-','_'),' ', substr($file, 0, (strlen ($file)) - (strlen (strrchr($file,'.')))))); echo '<tr><td><img src="' . $dir.'/'.$file .'" alt="'. $file .'" title="' . $file . '" width="200"></td><td>' . $caption . '</td></tr>'; } } } ?> Similar TutorialsHow can I save an image created on-the-fly on the server? For example, $img = "<img src=ChessImager/ChessImager.php?ds_color=(176,144,112)&ls_color=(224,200,160)&coordinates=on&square_size=$square_size&fen=" . urlencode($fen) . ">"; I can display the diagram, but I want to save these images with PHP. I have info being pulled from 2 tables, I need to know how I can order by date from both table intermixing.............like table 2 has the soonest timestamp, then table 1 has the next , then table 2 has the one after that, how do I make it display info in order of table 2 info, table 1 info, table 2, info...........here is code that I been trying to use: Code: [Select] <?php include 'config.php'; include 'opendb.php'; // if no id is specified, list the available articles if(!isset($_GET['id'])) { $query = "SELECT * FROM messages WHERE recipient ='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($from1, $recipient, $title1, $content, $id, $date, $read) = $row; if ($read == $userid){ $content1 .= "<br /><br /> $from1</p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title1</a>\r\n"; }else{ $content1 .= "<br /><br /> <strong>$from1</strong></p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title1</a>\r\n"; }} }else { // get the article info from database $query = "SELECT * FROM messages WHERE recipient='$name' ORDER by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; $to = $row['recipient']; $from = $row['from1']; $id = $row['id']; $read = $row['read']; } // if no id is specified, list the available articles if(!isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT * FROM comments WHERE recipient='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($com_id, $userid, $id1, $id, $recipient, $comment, $sender, $title, $date, $read) = $row; if ($read == $userid){ $content1 .= "<br /><br /> $from1</p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title</a>\r\n"; }else { $content1 .= "<br /><br /> <strong>$from1</strong></p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title</a>\r\n"; }} } else { // get the article info from database $query = "SELECT * FROM comments WHERE recipient='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $userid = $row['userid']; $id1 = $row['id1']; $id = $row['messageid']; $recipient = $row['recipient']; $comment = $row['comment']; $sender = $row['sender']; $title = $row['title']; $read = $row['read']; } include 'closedb.php'; ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309973.0 I have a posting system worked out, as well as my database configured to my linking.. But as of right now, my posts are posted from oldest to newest, having users scroll down or go to the next page to see the most recent post.
How would I "flip" that around and make my posts start from newest to oldest by its date/time (Which is stored in the database)?
Thanks!
I am trying to display images on a html page alphabetically in descending order by their filename. <?php $dir = "./plate_cache"; $handle = opendir($dir); while (($file = readdir($handle))!==false) { if (strpos($file, '.png',1)) { echo "<img id=\"plates\" src=\"/tags/plate_cache/$file\"></a><br />;"; } } closedir($handle); } ?> Any help is greatly appreciated! I have this script from http://lampload.com/...,view.download/ (I am not using a database) I can upload images fine, I can view files, but I want to delete them. When I press the delete button, nothing happens
http://www.jayg.co.u...oad_gallery.php
<form>
<?php $dir = dirname(__FILENAME__)."/images/gallery" ; $files1 = scandir($dir); foreach($files1 as $file){ if(strlen($file) >=3){ $foil = strstr($file, 'jpg'); // As of PHP 5.3.0 $foil = $file; $pos = strpos($file, 'css'); if ($foil==true){ echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />'; echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>"; } } }?> <input type="submit" name="mysubmit2" value="Delete"> </form>
any ideas please?
thanks
I am looking to display image paths in a row separated by commas. There are 6 images that goes to each user and I would like only the 6 images at be in each " " Like this: "images/listings/listing_516013019A-only.jpg,images/listings/listing_848813453A-1.jpg,images/listings/listing_664613453A-2.jpg,images/listings/listing_520313453A-3.jpg,images/listings/listing_690513453A-4.jpg,images/listings/listing_125113453A-5.jpg,images/listings/listing_641013453A-6.jpg," "images/listings/listing_736913186A-1.jpg,images/listings/listing_822713186A-2.jpg,images/listings/listing_136513186A-3.jpg,images/listings/listing_700313186A-4.jpg,images/listings/listing_716013186A-5.jpg,images/listings/listing_213113186A-6.jpg," "images/listings/listing_292113254A..-1.jpg,images/listings/listing_854413254A..-2.jpg,images/listings/listing_446013254A..-3.jpg,images/listings/listing_676313254A..-4.jpg,images/listings/listing_563413254A..-5.jpg,images/listings/listing_341513254A..-6.jpg," Right now it is displaying them like this "images/listings/listing_516013019A-only.jpg," "images/listings/listing_848813453A-1.jpg," "images/listings/listing_664613453A-2.jpg," "images/listings/listing_520313453A-3.jpg," "images/listings/listing_690513453A-4.jpg," "images/listings/listing_125113453A-5.jpg," "images/listings/listing_641013453A-6.jpg," "images/listings/listing_736913186A-1.jpg," "images/listings/listing_822713186A-2.jpg," "images/listings/listing_136513186A-3.jpg," "images/listings/listing_700313186A-4.jpg," "images/listings/listing_716013186A-5.jpg," "images/listings/listing_213113186A-6.jpg," "images/listings/listing_292113254A..-1.jpg," "images/listings/listing_854413254A..-2.jpg," "images/listings/listing_446013254A..-3.jpg," "images/listings/listing_676313254A..-4.jpg," "images/listings/listing_563413254A..-5.jpg," "images/listings/listing_341513254A..-6.jpg," Here is the code I have: Code: [Select] <?php // Make a MySQL Connection mysql_connect("localhost", "xxxxxxxx", "xxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxx") or die(mysql_error()); $result = mysql_query("SELECT * FROM listimages ORDER BY listimages.listingid DESC ") or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "\""; echo "$row[imagepath],"; echo "\""; echo "<br>"; } ?> My tables for the images is "listimages" and the columns a id (which are the auto_increments) imagepath (which shows the path/image1.jpg) mainimage (which just shows 0 or 1 depending on the picture that is the default for that listing, 1 being default) listingid (shows numbers 1 2 3 etc corresponding to the Id in the listings table to show what images go with what listing) There are up to 6 images for each listing. Any idea how to fix this? I read everywhere where it says not to stoe images in MYSQL but I have a code where I'm trying to display the images. They are all jpegs that are stored in the table. Here is the code Code: [Select] <?php include "dbaptsConfig.php"; include "searchaptsstyle.css"; // test id, you need to replace this with whatever id you want the result from $id = "1"; // what you want to ask the db $query = "SELECT * FROM `apartments` WHERE `id` = ".$id; // actually asking the db $res = mysql_query($query, $ms); // recieving the answer from the db (you can only use this line if there is always only one result, otherwise will give error) $result = mysql_fetch_assoc($res); // if you uncomment the next line it prints out the whole result as an array (prints out the image as weird characters) // print_r($result); // print out specific information (not the whole array) echo "<br/>"; echo "<div id='title'>".$result['title']."<br/></div>"; echo "<br/>"; echo "<div id='description'>".$result['description']."<br /></div>"; echo "<br/>"; echo "<div id='table'><tr>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Provider's Phone Number: ".$result['phone']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Provider: ".$result['service']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Borough: ".$result['county']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Town: ".$result['town']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Bedrooms: ".$result['rooms']."</td>"; echo "<td> </td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Bathrooms: ".$result['bath']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Square Footage: ".$result['square']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Rent: ".$result['rent']."<br /></td>"; echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Listed On: ".$result['time']."<br /></td>"; echo "</tr></div>"; header("Content-type: image/jpeg"); echo "<td bgcolor='#FFFFFF' style='color: #000' align='center'> Listed On: ".$result['image1']."<br /></td>"; ?> Thanks I want to display thumbnails for a picture gallery and when user clicks on image the larger image opens in a new window. I can't find a straight answer on the php.net website. Can someone help? I'm creating a funeral home site and on the side of the page I would like to display the last 5 funeral obituaries that are in mySQL database (name and certain sized image (images are in "image" field) w/ a link to an "obituaries detail page for the individual deceased person"). I am able to do this successfully listing only the names....how can I list the image associated with the name? This is what I have so far: Code: [Select] <?php include("connect.php"); ?> Code: [Select] <?php $query = "SELECT id, deceased_name, deceased_date, DATE_FORMAT(deceased_date, '%M %D, %Y') as datetext"; $query .= " FROM scales_obits ORDER BY deceased_date DESC LIMIT 5"; $listings = mysql_query($query); if (!listings) { echo("<p>Error retrieving listings from lookup table<br>". "Error: " . mysql_error()); exit(); } echo("<table border=\"0\" width=\"100%\" class=\"obit\">"); while ($listing = mysql_fetch_array($listings)) { $deceased_name = $listing["deceased_name"]; $deceased_date = $listing["datetext"]; $id = $listing["id"]; echo("<tr><td width=\"100%\"><a href=\"obitdetail.php?id=".$id."\"><strong>".$deceased_name."</strong></a></td><td> </td>"); } echo("</table>"); ?>
Hi everyone. I'm very new into self learning programming. Presently I'm trying to develop a simple basic Robot that would only Place a Market Order every seconds and it will cancel the Order every followed seconds. Using the following library: It would place Trade Order at a ( Price = ex.com api * Binance api Aggregate Trades Price) I have already wrote the api to call for xe.com exchange rate with php <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $k=>$to){ echo $k; // etc }; ?> And also for the Binance Aggregate Price in JavaScript
<script> var burl = "https://api3.binance.com"; var query = '/api/v3/aggTrades'; query += '?symbol=BTCUSDT'; var url = burl + query; var ourRequest = new XMLHttpRequest(); ourRequest.open('GET',url,true); ourRequest.onload = function(){ console.log(ourRequest.responseText); } ourRequest.send(); </script>
My problem is how to handle these two api responds and also the functions to use them to place a trade and cancel it. Hi everyone!! I have looked into how the upload script works and this is what i have: Code: [Select] <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Which is un-tested at the moment, but let's just say for talking sake it worked 100% what elements of this script would i be looking at to display the files uploaded on to another page, in my case my homepage? ive found as to yet, that the uploads have to be stored on a file somewhere on my server, which i've set up. But i thought it would be just as easy to have a field in my table named upload and display it within the table next to the other results? instead i just get whatever the file name is named.jpg. Any help in looking towards the answer? many thanks in advance guys! Hello everyone, I need help figuring out why im not getting images displayed. I have tried everything I could think of and narrowed down the issue. What Im doing id querying urls from DB for my images. Then using md5 to encrypting the url them before display on web page. Here is the code: Code: [Select] $img = @ md5(mysql_result(mysql_query("SELECT `url` FROM `pictures` WHERE `mls`='{$row['mls']}' ORDER BY `id` LIMIT 1",$avenu->link),0)); When html is displayed I get the hash.jpg. The image failed to be loaded. How can i display all the images in a certain directory and echo the image names. So if a new image is uploaded, it will still display without edited the gallery.php file. Cheers. Hi I tried to write a script: 1) to locate all directories in a directory (1 level) 2) with the function GetImages() I try to display the image(s) in the subfolder there are only images in the subfolder I guess I'm doing something wrong in the GetImages() with the glob function, can anyone check this ? Thanks in advance function GetImages($map) { $files = glob('$map/*.jpg'); //$files = glob("$map/*.*"); for ($i=0; $i<count($files); $i++) { $num = $files[$i]; echo '<img height="50" width="50" src="'.$num.'" />'." <br />"; } } if ($handle = opendir('mystuff')) { /* loop through directory. */ while (false !== ($dir = readdir($handle))) { if($dir != ".." && $dir != "."){ echo '<option value='.$dir.'>'.$dir.'</option><br>'; GetImages($dir); } } closedir($handle); } I want to retrieve an image id from a db and show the images. I cant get the syntax right for the image tag.Any help appreciated. Code: [Select] function display_covers() { global $wpdb; $query = "select * from wp_cover"; $result = mysql_query($query)or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); echo mysql_error(); if (!$result) return false; echo'<div class="wrap"><p>choose from one of the covers below</p></div>'; echo'<div id="main">'; echo'<table class="main" cellpadding="2">'; //echo"<caption>Please choose a book cover</caption>"; ?> <thead><tr><td colspan="5" ><h6 class="main">Book Covers</h6></td></tr> </thead> <?php $i=0; $size=3; echo "<tbody>"; echo "<tr>"; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { /* display picture */ ?> <td class="main"> <?php echo"<img src="/Applications/MAMP/htdocs/wordpress_3/wp-content/plugins/Authors2/jackets/"{.$row['pix'].}""/>"; echo"</td>"; $i++; if($i==$size) { echo "</tr><tr>"; $i=0; } } } Hi all, Newbie here, i am having a problem to get my images to show which are stored in mysql database as a mediumblob. I get id number to print in table ut am just getting empty square with red cross in where my image should be. Is my code incorrect or is it something else? Appreciate your help with this. I have included both of the pages codes i am using. Thanks Tony image2.php <?php include("common.php"); error_reporting(E_ALL); $link = mysql_connect(host,username,password) or die("Could not connect: " . mysql_error()); mysql_select_db(db) or die(mysql_error()); $sql = "SELECT id FROM photos"; $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); ?> <table border="1"><tr><td>id</td><td>image</td></tr> <?php while($row=mysql_fetch_assoc($result)){ print '<tr><td>'.$row['id'].'</td><td>'; print '<img src="image1.php?id='.$row['id'].'height="75" width="100"">'; } echo '</td></tr></table>' ?> image1.php <?php ob_start(); include("common.php"); mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); $query = mysql_query("SELECT imgage FROM photos WHERE id={$_GET['image_id']}"; $row = mysql_fetch_array($query); $content = $row['image']; header('Content-type: image/jpg'); echo $content; } ob_end_flush(); ?> Hello all, I need to make a rotating banner system for a client. They want about 5 banners to rotate with Javascript. However they want the visitor to sort of step through each one on each refresh. So if I have 5 banners and I go to the site, I see banner 1 and then the javascript rotates through each one. When I go back to the site, they want it to start with banner 2 and then the javascript will rotate through each one. Then on and on. Go back and see banner 3, then step through again. I have a nice Javascript image slider I'd like to use. It basically just requires the images in order. Like: <img src="1.jpg"/> <img src="2.jpg"/> <img src="3.jpg"/> <img src="4.jpg"/> <img src="5.jpg"/> I've thought about it and I think the best way to do this would just be using PHP and a cookie. So when the viewer first goes to the site, PHP checks for the cookie. If it exists, it pulls the starting image #. If it doesn't, it starts at 0 and sets the cookie. As for the images part, I figured an associate array would work well. The key would be what the cookie logic is based on, and then the image HTML would be in the array. So you visit the site without a cookie it would be... 0 => <img src="1.jpg"/> 1 => <img src="2.jpg"/> 2 => <img src="3.jpg"/> 3 => <img src="4.jpg"/> 4 => <img src="5.jpg"/> Then when you go back to the site, I need the array to be re-ordered like this: 0 => <img src="2.jpg"/> 1 => <img src="3.jpg"/> 2 => <img src="4.jpg"/> 3 => <img src="5.jpg"/> 4 => <img src="1.jpg"/> What's the best way to go about this array logic? My experience with manipulating data inside arrays is rather limited. Basically I need it to say "Start with key # and then reorder array based on that" I have a supplement store that we'll call SiteA . On the homepage there is a list of featured and best selling products with images. I have a separate blog that we'll call SiteB. I want to get the images and the url they link to (for the product page) from SiteA and display them on SiteB. So that when a user is browsing SiteB and they click on one of the product images, it takes them to the correct product page. I have a script where I can manually accomplish this. However, since the content on the homepage of SiteA is always changing, I'd like to automate this process. For example: If you do a google search for "php", then click on "images" at the top, you will see a list of images relevant to PHP. If you click on any one of them, it takes you to that images page. That is what I want to essentially accomplish. Any suggestions? |