Uploaded files arrive in wrong order
Posted: Thu Sep 11, 2008 3:44 am
Hi,
I'm trying to sort out my site's image upload and I'm finding that the images are appearing in the wrong order.
Here's the order I select them.

Here's my processing code:
When I display them I order them from the database by date and the file names go out of order (and count backwards but that doesn't really matter), and the images are out of sequence.
Here is the results I get:
http://www.getoutofglasgow.com/Trip29.htm
Hopefully you can explain what's going on because I can't make heads nor tails of it.
I'm trying to sort out my site's image upload and I'm finding that the images are appearing in the wrong order.
Here's the order I select them.

Here's my processing code:
Code: Select all
global $database, $session;
//set_time_limit(900);
define ("JPG", 2);
define ("PNG", 3);
$folder=getBasicFilename($referer);
if(!file_exists("../uploads/$folder")) {
mkdir("../uploads/$folder");
}
if(!file_exists("../uploads/$folder/small")) {
mkdir("../uploads/$folder/small");
}
$output="";
$errors=0;
$i=0;
foreach($_FILES as $file) {
$i=$i+1;
if($file["error"] == UPLOAD_ERR_OK) {
$filename=$file["name"];
$size=$file["size"];
$type=$file["type"];
$tmpname = $file["tmp_name"];
$filecount=$database->filecount($user);
if (is_uploaded_file($tmpname)) {
//Check file size under 2Mb
$maxsize=2;
//echo "Size: $size > $maxsize*1024*1024";
if($size <= $maxsize*1048576){
$pext = getFileExtension($filename);
$pext = strtolower($pext);
if ($pext == "jpg" || $pext == "jpeg" || $pext == "png")
{
$width = 0;
$height = 0;
$type = "";
$attr = "";
list($width, $height, $type, $attr) = @getimagesize($tmpname);
// Double check the file type - don't trust the extention
if ($type==JPG || $type==PNG )
{
$newname="$user".sprintf("%06d", $filecount).".$pext";
$destination="../uploads/incomplete/$newname";
if (!copy($tmpname, $destination))
{
$uploadform->setError("file_$i", "* Error uploading file $filename");
} else {
chmod($destination, 0400);
$res = $database->query("INSERT INTO newimages SET image='$newname', name='$user', page='$referer', filenumber='$filecount', date=now() ");
}
} else {
//echo "Bad file type";
$uploadform->setError("file_$i", "* Error uploading file $filename. Bad file type.");
}
} else {
//echo "Bad file type";
$uploadform->setError("file_$i", "* Error uploading file $filename. Bad file type.");
}
} else {
//echo "File to large - maximim is ".$maxsize."Mb.";
$uploadform->setError("file_$i", "* Error uploading file $filename. File to large - maximim is ".$maxsize."Mb.");
}
} else {
//echo "Error uploading file $filename";
$uploadform->setError("file_$i", "* Error uploading file $filename");
}
//Delete the temporary file
unlink($tmpname);
}
}
//set_time_limit(30);
header("Location: ".$referer);
Here is the results I get:
http://www.getoutofglasgow.com/Trip29.htm
Hopefully you can explain what's going on because I can't make heads nor tails of it.