Print in reverse order!
Posted: Tue Jun 07, 2005 5:43 pm
I have a photo upload system that after a photo uploads it tells you what photos have been uploaded. For some reason the order that it tells me is backwards, it lists the new upload at the bottom and I want it at the top. I was thinking array_reverse(); would solve my problem but I cannot seem to figure it out. Any help would be appreciated!
thumbs.php
upload.php
thumbs.php
Code: Select all
<?php
$thumb_dir = "thumbs/"; //The directory where you want your thumbs to be!
$dh = opendir("fullsize/"); //The directory where the full sized images are!
while ($f = readdir($dh)) {
echo call_user_func ('makethumb', $f);
}
function makethumb($file)
{
if (eregi(".(jpg|jpeg)$", $file))
if (!file_exists("$thumb_dir/$file")) { // checks to see if it is there!
$src = ImageCreateFromJPEG("fullsize/$file");
$filesize = filesize("fullsize/$file");
$org_h = imagesy($src);
$org_w = imagesx($src);
if ($org_h > $org_w) {
$height = 100; //The max size of the thumbnail!
$width = floor ($height * $org_w / $org_h);
}else {
$width = 100;
$height = floor ($width * $org_h / $org_w);
}
$img = ImageCreateTrueColor($width, $height);
ImageCopyResampled ($img, $src, 0, 0, 0, 0, $width, $height, $org_w, $org_h);
ImageJPEG($img, "thumbs/$file", 75);
print "<div align=\"center\"><b>$file</b> uploaded!<br></div>";
ImageDestroy ($img);
ImageDestroy ($src);
} else {
print "";
}
}
?>Code: Select all
<?php
session_start ();
if (! session_is_registered ( "mysessionvariable" ) ) //if your variable isn't there, then the session must not be
{
session_unset (); //so lets destroy whatever session there was and bring them to login page
session_destroy ();
$url = "Location: ../../../../assist/login.php";
header ( $url );
}
else
{
?>
<html>
<head>
<title>Upload photos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor=#FFFFFF text="#000000" leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
<p> </p>
<form method="post" enctype="multipart/form-data">
<p align="center"><font color="#333333" face="Courier New, Courier, mono">Photo
upload </font></p>
<p align="center"><font color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif"><font color="#990000">"jpg
or jpeg images only- <br>
Try to keep photos under 200k<br>
or it might not upload!"</font></font></p>
<table align=center border=0>
<tr>
<td>
<input type="file" size=30 name="photo1"><br>
</td>
</tr>
<tr>
<td align=center>
<input type="submit" name="submit" value="Upload">
</td>
</tr>
</table>
<div align="center">
<p> </p>
</div>
</form>
</body>
</html>
<?
if(isset( $submit )) {
if (file_exists ("fullsize/{$_FILES['photo1']['name']}")){
print "<div align=\"center\"><font color=\"#FF0000\"><b>ERROR:</font></b> <b>{$_FILES['photo1']['name']}</b> already exists!</div>";
}else {
copy ($_FILES['photo1']['tmp_name'], "fullsize/".$_FILES['photo1']['name']) or die ("Could not upload image #1.");
$fpphoto = fopen('_photos.txt', 'r');
$old_content = filesize('_photos.txt')?fread($fpphoto, filesize('_photos.txt')):"";
$fp = fopen('_photos.txt', 'w');
fwrite($fp, "<a href='photo/fullsize/".$_FILES['photo1']['name']."' target='_blank'><img src='photo/thumbs/".$_FILES['photo1']['name']."' border=0></a> \r\n$old_content", (strlen($old_content) + 16 + 256));
fclose($fpphoto);
fclose($fp);
include "thumbs.php";
}
}
?>
<?php
}
?>