I have built an image upload with the help of the community and would like to release it as a snippet. Its great for learning and even just grabbing small pieces of data from it and ripping it apart.

The features are
  • compact code
  • unique file identifier
  • numbers files with a +1 increment, starting with 1 as the first file
  • can add a word infront of it, for example a session username or a first name
  • can add as many file boxes as needed
  • converts images to jpg in both the original format and new thumb version.
  • thumb can set a max width and the height becomes proportional so it doesn't become distorted
  • 2 different directories to separate thumb and original
  • can grab image data so it can be inserted into a database very easily.

Here is the final code, it is a useful snippet for any body who wants to rip it apart.

PHP Code:
if (isset($_POST['addpart'])) {
$image $_FILES['images']['tmp_name'];
$name  $_POST['username'];
$i     0;
$i2    1;
$id    uniqid();
        foreach (
$image as $key) {
$fileData   pathinfo(basename($_FILES["images"]["name"][$i]));
$fileName[] = $name '_' $id '_' $i2 '.' $fileData['name'] . 'jpg';
move_uploaded_file($key"image/" end($fileName));
$images     "image/" end($fileName);
$new_images "image_thumbnail/" end($fileName);
$width      100//*** Fix Width & Heigh (Autu caculate) ***//
$size       GetimageSize($images);
$height     round($width $size[1] / $size[0]);
            switch (
$size[2]) {
$images_orig imagecreatefromgif($images);
$images_orig imagecreatefromjpeg($images);
$images_orig imagecreatefrompng($images);
"Unknown filetype");
//$images_orig = imagecreatefromjpeg($images);
$photoX     ImagesX($images_orig);
$photoY     ImagesY($images_orig);
$images_fin ImageCreateTrueColor($width$height);
ImageCopyResampled($images_fin$images_orig0000$width 1$height 1$photoX$photoY);
'Uploaded<br />';
'Main Image - ' $fileName[0] . '<br />';
'Extra Image 1 - ' $fileName[1] . '<br />';
'Extra Image 2 - ' $fileName[2] . '<br />';
    <form action="" method="post" enctype="multipart/form-data" id="form">
    username - <input name="username" type="text" id="username" size="50" /><br>
    Main Image - <input name="images[]" type="file" id="images[]" size="50" accept="image/jpeg" /><br>
    Extra Image 1 - <input name="images[]" type="file" id="images[]" size="50" accept="image/jpeg" /><br>
    Extra Image 2 - <input name="images[]" type="file" id="images[]" size="50" accept="image/jpeg" /><br>
    <input type="submit" name="addpart" value="Upload" /><br>