Image upload with monitoring

I’ve been playing about with this most of the afternoon

[php]

<?php $file_dir = "uploads/temp/"; if($_POST['upload']) { # edit # $maxwidth = 280; $maxheight = 210; $max_filesize = 102400; $types_array = array('image/pjpeg'); # end edit # $i=0; if($_FILES['image']['name'][$i] == "") { echo "Please select a file to upload!n"; exit; } if(!in_array($_FILES['image']['type'][$i], $types_array)) { echo "That file type is not allowed!!. You can only upload image files with JPGextensions.n"; exit; } $max_filesize_kb = ($max_filesize / 1024); if($_FILES['image']['size'][$i] > $max_filesize) { echo "You file is too large, files may be up to ".$max_filesize_kb."kbn"; exit; } $imagesize = getimagesize($_FILES['image']['tmp_name']); $imagewidth = $imagesize[0]; $imageheight = $imagesize[1]; if($imagewidth > $maxwidth || $imageheight > $maxheight) { echo "You file is too large, files may be up to ".$maxwidth."px x ".$maxheight."px in sizen"; end; } if (trim($_FILES['image']['name'][$i]) != "") { $k=0; $newfile = $file_dir . "$k.jpg"; if (file_exists($newfile)) { if ($handle = opendir($file_dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files[] = $file; } } closedir($handle); } $k = count($files) + 1; } $newfile = $file_dir . "$k.jpg"; move_uploaded_file($_FILES['image']['tmp_name'][$i], $newfile); } } ?>

[/php]

with this in the body

[php]

<?php $tot_img = 6; if ($handle = opendir('uploads/temp/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files[] = array($file); } } closedir($handle); } $img_put = count($files); $img_left = $tot_img - $img_put; echo "Your have ".$img_put." images on file, you can upload ".$img_left." more images"; if(count($files) < $tot_img) { ?> <?php } if ($handle = opendir('uploads/temp')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files[] = array($file); ?>
<?php
    } 
} 
closedir($handle); 

}

?>

[/php]

What its supposed to do is check image size, type, width and so on and also check the amount of images uploaded.

Whats happening is its throwing up some weird values in the calculation.

Can anyone shed some light on this

I’ve moved the upload script to anoth directory and its working fine now.

But if somebody knows why this happened can you let me know please.

Sponsor our Newsletter | Privacy Policy | Terms of Service