pneudralics Posted January 18, 2009 Share Posted January 18, 2009 I upload pictures with ftp or through a script to a folder. How do I display the 3 latest uploaded picture from the folder to a page? Link to comment https://forums.phpfreaks.com/topic/141292-how-do-i-display-the-latest-uploaded-picture-on-a-page/ Share on other sites More sharing options...
CyberShot Posted January 18, 2009 Share Posted January 18, 2009 are you using any kind of cms? What is your site? Link to comment https://forums.phpfreaks.com/topic/141292-how-do-i-display-the-latest-uploaded-picture-on-a-page/#findComment-739528 Share on other sites More sharing options...
dropfaith Posted January 18, 2009 Share Posted January 18, 2009 yea we need more info to solve this show the script you use to upload and that should help alot Link to comment https://forums.phpfreaks.com/topic/141292-how-do-i-display-the-latest-uploaded-picture-on-a-page/#findComment-739541 Share on other sites More sharing options...
dawsba Posted January 18, 2009 Share Posted January 18, 2009 amend this as you need <? function sortarrayByDate($array,$dir) { $temp = $array; $temp2 = array(); $targetdir = getcwd()."/".$dir; foreach($temp as $key => $i){ $modifyDate = floatval(date("YmdHis", (filemtime($targetdir.$i)))); if($key < 10){ $temp2[$i] = floatval($modifyDate."0000".$key); } elseif($key < 99){ $temp2[$i] = floatval($modifyDate."000".$key); } elseif($key < 999){ $temp2[$i] = floatval($modifyDate."00".$key); } elseif($key < 9999){ $temp2[$i] = floatval($modifyDate."0".$key); } else{ $temp2[$i] = floatval($modifyDate.$key); } } arsort($temp2); $counter = 0; foreach($temp2 as $key => $value){ $temp[$counter] = $key; $counter++; } return $temp; } $targetdir = getcwd()."/docs"; $files = array(); $directory = opendir($targetdir); while($filename = readdir($directory)) { if(strlen($filename) > 2) { array_push($files, $filename); } } $files = sortarrayByDate($files,'docs'); ?> Link to comment https://forums.phpfreaks.com/topic/141292-how-do-i-display-the-latest-uploaded-picture-on-a-page/#findComment-739657 Share on other sites More sharing options...
pneudralics Posted January 18, 2009 Author Share Posted January 18, 2009 This is my upload script. No I'm not using any cms. <?php //This is the page for uploading the gallery section session_start(); if(!isset($_SESSION['username'])){ require ("error.php"); } else { include ('header.php'); ?> <table width="800" align="center"> <tr> <td align="center"> This section uploads the images to the Gallery section. <br /> This will change the image name to a random 32 character name and the extension to .jpg. <br /> Recommend 800px max width for the images or it'll start stretching the pages. <br /> To delete images click the View Gallery below, click the image you want to delete and click delete. </td> </tr> <tr> <td> <br /> [<a href="gallery.php">Delete Images</a>] <br /> <br /> <?php //Image variable/constant image folder upload $galleryupload = GALLERYUPLOAD; if (isset($_POST['submit'])) { //Start image upload //Check for an image make new name with md5 $newname = md5(time()*rand(1,99999).$_FILES['image']['name']); $newname2 = $newname.'.jpg'; //Check for main image if (move_uploaded_file ($_FILES['image']['tmp_name'], GALLERYUPLOAD."$newname2")) { echo '<font color="red">Image uploaded successfully.</font><br />'; } else { echo '<font color="red">Problem uploading image.</font><br />'; } }//End isset submit ?> <form enctype="multipart/form-data" action="gallery.php" method="post"> <b>Upload Gallery Image</b> (100KB Max) <br /> <input type="hidden" name="MAX_FILE_SIZE" value="102400" /> <input type="file" name="image" size="50" /> <br /> <br /> <input type="submit" name="submit" value="UPLOAD" /> </form> </td> </tr> </table> <?php }//End session else ?> Link to comment https://forums.phpfreaks.com/topic/141292-how-do-i-display-the-latest-uploaded-picture-on-a-page/#findComment-739974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.