Jump to content

How do I display the latest uploaded picture on a page?


pneudralics

Recommended Posts

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');
?>

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
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.