[SOLVED I THINK] How to upload multiple image files and insert file name in to a database

I’m trying to upload some 3 or 4 image files and then insert the file names in to 4 columns. I’m using the below listed code base. The uploading part of the script is working with out any problems but entering the file name part is giving an issue is there way to over come this if there another way to archives this please let me know.

This is not my handy work I’m using a script called easy PHP uploader this users another script called upload_class.php this works wonders when used to upload just one file.

Multi upload part
if($_FILES[‘upload’][‘name’])
{

    $max_size = 10000*10000; // the max. size for uploading

    class muli_files extends file_upload {

        var $number_of_files = 0;
        var $names_array;
        var $tmp_names_array;
        var $error_array;
        var $wrong_extensions = 0;
        var $bad_filenames = 0;

        function extra_text($msg_num) {
            switch ($this->language) {
                case "de":
                    // add you translations here
                    break;
                default:
                    $extra_msg[1] = "Error for: <b>".$this->the_file."</b>";
                    $extra_msg[2] = "You have tried to upload ".$this->wrong_extensions." files with a bad extension, the following extensions are allowed: <b>".$this->ext_string."</b>";
                    $extra_msg[3] = "Select at least on file.";
                    $extra_msg[4] = "Select the file(s) for upload.";
                    $extra_msg[5] = "You have tried to upload <b>".$this->bad_filenames." files</b> with invalid characters inside the filename.";
            }
            return $extra_msg[$msg_num];
        }
        // this method checkes the number of files for upload
        // this example works with one or more files
        function count_files() {
            foreach ($this->names_array as $test) {
                if ($test != "") {
                    $this->number_of_files++;
                }
            }
            if ($this->number_of_files > 0) {
                return true;
            } else {
                return false;
            }
        }
        function upload_multi_files () {
            $this->message = "";
            if ($this->count_files()) {
                foreach ($this->names_array as $key => $value) {
                    if ($value != "") {
                        $this->the_file = $value;
                        $new_name = $this->set_file_name();
                        if ($this->check_file_name($new_name)) {
                            if ($this->validateExtension()) {
                                $this->file_copy = $new_name;
                                $this->the_temp_file = $this->tmp_names_array[$key];
                                if (is_uploaded_file($this->the_temp_file)) {
                                    if ($this->move_upload($this->the_temp_file, $this->file_copy)) {
                                        $this->message[] = $this->error_text($this->error_array[$key]);
                                        if ($this->rename_file) $this->message[] = $this->error_text(16);
                                        sleep(1); // wait a seconds to get an new timestamp (if rename is set)
                                    }
                                } else {
                                    $this->message[] = $this->extra_text(1);
                                    $this->message[] = $this->error_text($this->error_array[$key]);
                                }
                            } else {
                                $this->wrong_extensions++;
                            }
                        } else {
                            $this->bad_filenames++;
                        }
                    }
                }
                if ($this->bad_filenames > 0) $this->message[] = $this->extra_text(5);
                if ($this->wrong_extensions > 0) {
                    $this->show_extensions();
                    $this->message[] = $this->extra_text(2);
                }
            } else {
                $this->message[] = $this->extra_text(3);
            }
        }
    }

    $multi_upload = new muli_files;

    $multi_upload->upload_dir = "uploads/"; // "files" is the folder for the uploaded files (you have to create this folder)
    $multi_upload->extensions = array(".png",".jpeg",".jpg"); // specify the allowed extensions here
    $multi_upload->message[] = $multi_upload->extra_text(4); // a different standard message for multiple files
    //$multi_upload->rename_file = true; // set to "true" if you want to rename all files with a timestamp value
    $multi_upload->do_filename_check = "y"; // check filename ...
    $multi_upload->tmp_names_array = $_FILES['upload']['tmp_name'];
    $multi_upload->names_array = $_FILES['upload']['name'];
    $multi_upload->error_array = $_FILES['upload']['error'];
    $multi_upload->upload_multi_files();
    //$my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
    //$my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
    //$new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
    if ($multi_upload->upload()) { // new name is an additional filename information, use this to rename the uploaded file
        $full_path = $multi_upload->upload_dir.$multi_upload->file_copy;
        $imagename = $multi_upload->get_uploaded_file_info($full_path);
    }

}
else
{
    $imagename = "" ;
}

upload_class.php

<?php 
/*
Easy PHP Upload - version 2.33
A easy to use class for your (multiple) file uploads

Copyright (c) 2004 - 2011, Olaf Lederer
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the finalwebsites.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

_________________________________________________________________________
available at http://www.finalwebsites.com/snippets.php?id=7
Comments & suggestions: http://www.finalwebsites.com/blog/submit-a-question/

*************************************************************************/
 
class file_upload {

    var $the_file;
    var $the_temp_file;
    var $the_mime_type; // new in 2.33
    var $upload_dir;
    var $replace;
    var $do_filename_check;
    var $max_length_filename = 100;
    var $extensions;
    var $valid_mime_types = array('.bmp'=>'image/bmp', '.gif'=>'image/gif', '.jpg'=>'image/jpeg', '.jpeg'=>'image/jpeg', '.pdf'=>'application/pdf', '.png'=>'image/png', '.zip'=>'application/zip'); // new in 2.33 (search google for a complete list)
    var $ext_string;
    var $language;
    var $http_error;
    var $rename_file; // if this var is true the file copy get a new name
    var $file_copy; // the new name
    var $message = array();
    var $create_directory = true;
    /* 
    ver. 2.32 
    Added vars for file and directory permissions, check also the methods move_upload() and check_dir().
    */
    var $fileperm = 0644;
    var $dirperm = 0755; 
    
    function file_upload() {
        $this->language = 'en'; // choice of en, nl, es
        $this->rename_file = false;
        $this->ext_string = '';
    }
    function show_error_string($br = '<br />') {
        $msg_string = '';
        foreach ($this->message as $value) {
            $msg_string .= $value.$br;
        }
        return $msg_string;
    }
    function set_file_name($new_name = '') { // this 'conversion' is used for unique/new filenames 
        if ($this->rename_file) {
            if ($this->the_file == '') return;
            $name = ($new_name == '') ? strtotime('now') : $new_name;
            sleep(3);
            $name = $name.$this->get_extension($this->the_file);
        } else {
            $name = str_replace(' ', '_', $this->the_file); // space will result in problems on linux systems
        }
        return $name;
    }
    function upload($to_name = '') {
        $new_name = $this->set_file_name($to_name);
        if ($this->check_file_name($new_name)) {
            if ($this->validateExtension()) {
                if (is_uploaded_file($this->the_temp_file)) {
                    $this->file_copy = $new_name;
                    if ($this->move_upload($this->the_temp_file, $this->file_copy)) {
                        $this->message[] = $this->error_text($this->http_error);
                        if ($this->rename_file) $this->message[] = $this->error_text(16);
                        return true;
                    }
                } else {
                    $this->message[] = $this->error_text($this->http_error);
                    return false;
                }
            } else {
                $this->show_extensions();
                $this->message[] = $this->error_text(11);
                return false;
            }
        } else {
            return false;
        }
    }
    function check_file_name($the_name) {
        if ($the_name != '') {
            if (strlen($the_name) > $this->max_length_filename) {
                $this->message[] = $this->error_text(13);
                return false;
            } else {
                if ($this->do_filename_check == 'y') {
                    if (preg_match('/^[a-z0-9_]*\.(.){1,5}$/i', $the_name)) {
                        return true;
                    } else {
                        $this->message[] = $this->error_text(12);
                        return false;
                    }
                } else {
                    return true;
                }
            }
        } else {
            $this->message[] = $this->error_text(10);
            return false;
        }
    }
    function get_extension($from_file) {
        $ext = strtolower(strrchr($from_file,'.'));
        return $ext;
    }
    /* New in version 2.33 */
    function validateMimeType() {
        $ext = $this->get_extension($this->the_file);
        if ($this->the_mime_type == $this->valid_mime_types[$ext]) {
            return true;
        } else {
            $this->message[] = $this->error_text(18);
            return false;
        }
    }
    /* Added here the mime check in ver. 2.33 */
    function validateExtension() {
        $extension = $this->get_extension($this->the_file);
        $ext_array = $this->extensions;
        if (in_array($extension, $ext_array)) {
            if (!empty($this->the_mime_type)) {
                if ($this->validateMimeType()) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return true;
            }
        } else {
            return false;
        }
    }
    // this method is only used for detailed error reporting
    function show_extensions() {
        $this->ext_string = implode(' ', $this->extensions);
    }
    function move_upload($tmp_file, $new_file) {
        if ($this->existing_file($new_file)) {
            $newfile = $this->upload_dir.$new_file;
            if ($this->check_dir($this->upload_dir)) {
                if (move_uploaded_file($tmp_file, $newfile)) {
                    umask(0);
                    chmod($newfile , $this->fileperm);
                    return true;
                } else {
                    return false;
                }
            } else {
                $this->message[] = $this->error_text(14);
                return false;
            }
        } else {
            $this->message[] = $this->error_text(15);
            return false;
        }
    }
    function check_dir($directory) {
        if (!is_dir($directory)) {
            if ($this->create_directory) {
                umask(0);
                mkdir($directory, $this->dirperm);
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }
    function existing_file($file_name) {
        if ($this->replace == 'y') {
            return true;
        } else {
            if (file_exists($this->upload_dir.$file_name)) {
                return false;
            } else {
                return true;
            }
        }
    }
    /*
    ver. 2.32 
    Method get_uploaded_file_info(): Replaced old \n line-ends with the PHP constant variable PHP_EOL
    */
    function get_uploaded_file_info($name) {
        $str = 'File name: '.basename($name).PHP_EOL;
        $str .= 'File size: '.filesize($name).' bytes'.PHP_EOL;
        if (function_exists('mime_content_type')) {
            $str .= 'Mime type: '.mime_content_type($name).PHP_EOL;
        }
        if ($img_dim = getimagesize($name)) {
            $str .= 'Image dimensions: x = '.$img_dim[0].'px, y = '.$img_dim[1].'px'.PHP_EOL;
        }
        return $str;
    }
    // this method was first located inside the foto_upload extension
    function del_temp_file($file) {
        $delete = @unlink($file); 
        clearstatcache();
        if (@file_exists($file)) { 
            $filesys = eregi_replace('/','\\',$file); 
            $delete = @system('del $filesys');
            clearstatcache();
            if (@file_exists($file)) { 
                $delete = @chmod ($file, 0644); 
                $delete = @unlink($file); 
                $delete = @system('del $filesys');
            }
        }
    }
    // this function creates a file field and if $show_alternate is true it will show a text field if the given file already exists
    // there is also a submit button to remove the text field value 
    /*
    ver. 2.32 
    Method create_file_field(): Minor code clean up (better code formatting and replaced double with single quotes)
    */
    function create_file_field($element, $label = '', $length = 25, $show_replace = true, $replace_label = 'Replace old file?', $file_path = '', $file_name = '', $show_alternate = false, $alt_length = 30, $alt_btn_label = 'Delete image') {
        $field = '';
        if ($label != '') $field = '
            <label>'.$label.'</label>';
        $field = '
            <input type="file" name="'.$element.'" size="'.$length.'" />';
        if ($show_replace) $field .= '
            <span>'.$replace_label.'</span>
            <input type="checkbox" name="replace" value="y" />';
        if ($file_name != '' && $show_alternate) {
            $field .= '
            <input type="text" name="'.$element.'" size="'.$alt_length.'" value="'.$file_name.'" readonly="readonly"';
            $field .= (!@file_exists($file_path.$file_name)) ? ' title="'.sprintf($this->error_text(17), $file_name).'" />' : ' />';
            $field .= '
            <input type="checkbox" name="del_img" value="y" />
            <span>'.$alt_btn_label.'</span>';
        } 
        return $field;
    }
    // some error (HTTP)reporting, change the messages or remove options if you like.
    /* ver 2.32 
    Method error_text(): Older Dutch language messages are re-written, thanks Julian A. de Marchi. Added HTTP error messages (error 6-7 introduced with newer PHP versions, error no. 5 doesn't exists) 
    */
    function error_text($err_num) {
        switch ($this->language) {
            case 'nl':    
            $error[0] = 'Bestand <b>'.$this->the_file.'</b> staat nu op de server.';
            $error[1] = 'Dit bestand is groter dan de toegestaane upload bestandgrootte in de server configuratie.';
            $error[2] = 'Dit bestand is groter dan de MAX_FILE_SIZE parameter welke in de html formulier werdt gespecificiëerd.';
            $error[3] = 'De upload is helaas mislukt.  Slechts een deel van het bestand is bij de server aangekomen.  Probeer het opnieuw.';
            $error[4] = 'De upload is helaas mislukt.  Geen betrouwbare verbinding met de server kwam tot stand.  Probeer het opnieuw.';
            $error[6] = 'De map voor tijdelijke opslag ontbreekt. ';
            $error[7] = 'Het schrijven op de server is mislukt. ';
            $error[8] = 'Een PHP extensie is gestopt tijdens het uploaden. ';
            // end  http errors
            $error[10] = 'Selecteer een bestand om te uploaden.';
            $error[11] = 'Uitsluitend bestanden van de volgende types zijn toegestaan: <b>'.$this->ext_string.'</b>';
            $error[12] = 'Helaas heeft het gekozen bestand karakters die niet zijn toegestaan. Gebruik uitsluitend cijfers, letters, en onderstrepen. <br>Een geldige naam eindigt met een punt met daarop volgend het extensietype.';
            $error[13] = 'De bestandsnaam is echter te lang, en mag een maximum van '.$this->max_length_filename.' tekens bevatten.';
            $error[14] = 'De gekozen map werdt niet gevonden.';
            $error[15] = 'Een bestand met dezelfde naam ('.$this->the_file.') bestaat al op de server.  Probeer opnieuw met een andere naam.';
            $error[16] = 'Op de server werdt het bestand hernoemd tot <b>'.$this->file_copy.'</b>.';
            $error[17] = 'Het bestand %s bestaat niet.';
            $error[18] = 'De soort bestand (mime type) is niet toegestaan.'; // new ver. 2.33
            break;
            case 'de':
            $error[0] = 'Die Datei: <b>'.$this->the_file.'</b> wurde hochgeladen!'; 
            $error[1] = 'Die hochzuladende Datei ist gr&ouml;&szlig;er als der Wert in der Server-Konfiguration!'; 
            $error[2] = 'Die hochzuladende Datei ist gr&ouml;&szlig;er als der Wert in der Klassen-Konfiguration!'; 
            $error[3] = 'Die hochzuladende Datei wurde nur teilweise &uuml;bertragen'; 
            $error[4] = 'Es wurde keine Datei hochgeladen';
            $error[6] = 'Der tempor&auml;re Dateiordner fehlt';
            $error[7] = 'Das Schreiben der Datei auf der Festplatte war nicht m&ouml;glich.';
            $error[8] = 'Eine PHP Erweiterung hat w&auml;hrend dem hochladen aufgeh&ouml;rt zu arbeiten. '; 
            
            $error[10] = 'W&auml;hlen Sie eine Datei aus!.'; 
            $error[11] = 'Es sind nur Dateien mit folgenden Endungen erlaubt: <b>'.$this->ext_string.'</b>';
            $error[12] = 'Der Dateiname enth&auml;lt ung&uuml;ltige Zeichen. Benutzen Sie nur alphanumerische Zeichen f&uuml;r den Dateinamen mit Unterstrich. <br>Ein g&uuml;ltiger Dateiname endet mit einem Punkt, gefolgt von der Endung.'; 
            $error[13] = 'Der Dateiname &uuml;berschreitet die maximale Anzahl von '.$this->max_length_filename.' Zeichen.'; 
            $error[14] = 'Das Upload-Verzeichnis existiert nicht!'; 
            $error[15] = 'Upload <b>'.$this->the_file.'...Fehler!</b> Eine Datei mit gleichem Dateinamen existiert bereits.';
            $error[16] = 'Die hochgeladene Datei ist umbenannt in <b>'.$this->file_copy.'</b>.';
            $error[17] = 'Die Datei %s existiert nicht.';
            $error[18] = 'Der Datei Typ (mime type) ist nicht erlaubt.'; // new ver. 2.33
            break;
            //
            // place here the translations (if you need) from the directory 'add_translations'
            //
            default:
            // start http errors
            $error[0] = 'File: <b>'.$this->the_file.'</b> successfully uploaded!';
            $error[1] = 'The uploaded file exceeds the max. upload filesize directive in the server configuration.';
            $error[2] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.';
            $error[3] = 'The uploaded file was only partially uploaded';
            $error[4] = 'No file was uploaded';
            $error[6] = 'Missing a temporary folder. ';
            $error[7] = 'Failed to write file to disk. ';
            $error[8] = 'A PHP extension stopped the file upload. ';
            
            // end  http errors
            $error[10] = 'Please select a file for upload.';
            $error[11] = 'Only files with the following extensions are allowed: <b>'.$this->ext_string.'</b>';
            $error[12] = 'Sorry, the filename contains invalid characters. Use only alphanumerical chars and separate parts of the name (if needed) with an underscore. <br>A valid filename ends with one dot followed by the extension.';
            $error[13] = 'The filename exceeds the maximum length of '.$this->max_length_filename.' characters.';
            $error[14] = 'Sorry, the upload directory does not exist!';
            $error[15] = 'Uploading <b>'.$this->the_file.'...Error!</b> Sorry, a file with this name already exitst.';
            $error[16] = 'The uploaded file is renamed to <b>'.$this->file_copy.'</b>.';
            $error[17] = 'The file %s does not exist.';
            $error[18] = 'The file type (mime type) is not valid.'; // new ver. 2.33
        }
        return $error[$err_num];
    }
}
?

What’s the issue you are getting?

Issue is it’s not entering the file names to the data base it’s uploading the files with out any errors but not catching the file names so I can use the query to enter them under image 1, image 2 image 3 … etc columns.

Well for starters i’d change your count_files check to just be:

count(array_filter($names_array, 'strlen'));

(or filter your names array to begin with, that way you dont need so many “if ($value != “”)” checks.)

The trouble seems to be eminating from this line:

$new_name = $this->set_file_name();

I see no function defined for set_file_name in the class… are you including a parent class file_upload somewhere?

This is not my work m8 this is a script called Easy PHP uploader which have a upload_class.php and this is a addon function kinda of a thing I’ll add both scripts so it will be easy.

have tries almost everything almost at the point where I give up bro.

ok I removed the if condition at the end of the multiple file upload and started to work now I use this code to do the work the last part of the code gives me the name but when I echo it only shows one name when I upload 2 files.

if($_FILES['upload']['name'])
{

    $max_size = 1000*1000; // the max. size for uploading
    $multi_upload = new muli_files;
    $multi_upload->upload_dir = "uploads/"; // "files" is the folder for the uploaded files (you have to create this folder)
    $multi_upload->extensions = array(".png",".jpeg",".jpg"); // specify the allowed extensions here
    // $multi_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
    $multi_upload->max_length_filename = 1000; // change this value to fit your field length in your database (standard 100)
    $multi_upload->rename_file = true;
    $multi_upload->tmp_names_array = $_FILES['upload']['tmp_name'];
    $multi_upload->names_array = $_FILES['upload']['name'];
    $multi_upload->error_array = $_FILES['upload']['error'];
    //$multi_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
    //$multi_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
    //$new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
    $multi_upload->upload_multi_files();// new name is an additional filename information, use this to rename the uploaded file
        $full_path = $multi_upload->upload_dir.$multi_upload->file_copy;
        $imagename[] = $multi_upload->get_uploaded_file_info($full_path);

    $img = implode(", ",$imagename);

    echo $img;


}
else
{
    $imagename = "" ;
}

I just want to know if there’s way to get all the names ??

The uploading part of the files works but not name getting added to data base.

should I drop the auto rename and try something like this’

  $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];

  $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];

  $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];

Well I tried my best to find a solution to this any way I didn’t get any but I figured out a way to do this it’s not pretty but it works code is below.

action.php

<?php
/**
 * Created by PhpStorm.
 * User: SiNUX
 * Date: 9/13/14
 * Time: 9:44 PM
 */
include_once("hostcon.php");
include_once("Scirpts/multiupload.php");

$rName = validateInput(mysql_real_escape_string($_POST["name"]));
$nicName = validateInput(mysql_real_escape_string($_POST["nicname"]));
$age = validateInput(mysql_real_escape_string($_POST["age"]));
$bust = validateInput(mysql_real_escape_string($_POST["bust"]));
$size = validateInput(mysql_real_escape_string($_POST["size"]));
$height = mysql_real_escape_string($_POST["height"]);
$hair = validateInput(mysql_real_escape_string($_POST["hair"]));
$eyes = mysql_real_escape_string($_POST["eyes"]);
$nAtio = validateInput(mysql_real_escape_string($_POST["natio"]));
$dEscrip = validateInput(mysql_real_escape_string($_POST["desc"]));
$stdService = $_POST["stdService"];
$othService $_POST["othService"];
$img1 = $_FILES['upload']['name'][0];
$img2 = $_FILES['upload']['name'][1];
$img3 = $_FILES['upload']['name'][2];
$img4 = $_FILES['upload']['name'][3];

//Adds data from the options array in to one line
$std = implode(", ",$stdService);
$oth = implode(", ",$othService);

function validateInput($frmData){
    $frmData = trim($frmData);
    $frmData = stripslashes($frmData);
    $frmData = htmlspecialchars($frmData);

    return $frmData;

}

//----------------------------------------- Start of data verification ------------------------------------------------
//Initiate error variable as empty
$errorCount = "";

//Start comparing and binding of the error variable with the message
//If error passed on with an error message it will stop the adding of the data to table and then send a message
//To be displayed to why the data was not entered.
if (empty($rName)) {
    $errorCount = $errorCount. "Name cannot be empty";
} else {
     if (!preg_match("/^[a-zA-Z]+$/", $rName)) {
          $errorCount = $errorCount . "Only Letters and White Space Allowed";
     }
}

if(empty($nicName)){
   $errorCount = $errorCount . ", Nick name cannot be empty";
}else{
    if(!preg_match("/^[a-zA-Z0-9]+$/",$nicName)){
        $errorCount = $errorCount .", Only Letters, White Space and numbers Allowed";
    }
}

if(empty($age)){
     $errorCount = ", Age cannot be empty";
 }else{
     if(!preg_match("/^[0-125]+$/", $age)){
         $errorCount = $errorCount .", Only numbers are allowed";
     }
 }

if(empty($bust)){
    $errorCount = $errorCount.", Bust cannot be empty";
}else{
    if(!preg_match("/^[0-9]+$/", $bust)){
        $errorCount = $errorCount .", Only numbers are allowed";
    }
}

if(empty($size)){
    $errorCount = $errorCount.", Size cannot be empty";
}else{
    if(!preg_match("/^[0-9]+$/", $size)){
        $errorCount = $errorCount .", Only numbers are allowed";
    }
}

if(empty($height)){
    $errorCount = $errorCount.", Height cannot be empty";
}

if(empty($hair)){
    $errorCount = $errorCount.", Hair cannot be empty";
}else{
    if(!preg_match("/^[a-zA-Z]+$/", $hair)){
        $errorCount = $errorCount .", Only Letters and White Space Allowed";
    }
}

if(empty($nAtio)){
    $errorCount = $errorCount.", Nationality cannot be empty";
}else{
    if(!preg_match("/^[a-zA-Z]+$/", $nAtio)){
        $errorCount = $errorCount .", Only Letters and White Space Allowed";
    }
}

if(empty($dEscrip)){
    $errorCount = $errorCount.", Description cannot be empty";
}else{
    if(!preg_match("/^[a-zA-Z]+$/", $dEscrip)){
        $errorCount = $errorCount .", Only Letters and White Space Allowed";
    }
}

//verify image name so it wont duplicate
if(empty($img1 || $img2 || $img3 || $img4)){
    $img1 = "default.jpg";
}

$getImgData = "SELECT * FROM modeldetails WHERE img1='".$img1. "' AND img2 = '".$img2."' AND img3='".$img3."'AND img4='".$img4."'";
$runQuary = mysql_query($getImgData);

$num = mysql_num_rows($runQuary);
$row = mysql_fetch_array($runQuary);

if($num > 0){
    if($row['img1']){
        $errorCount = $errorCount.", ".$img1." file is already in the data base";
    }else if($row['img2']){
        $errorCount = $errorCount.", ".$img2." file is already in the data base";
    }else if($row['img3']){
        $errorCount = $errorCount.", ".$img3." file is already in the data base";
    }else if($row['img4']){
        $errorCount = $errorCount.", ".$img4." file is already in the data base";
    }
}

//------------------------------------------- end of data verifying ---------------------------------------------------

if($_FILES['upload']['name'])
{

    $max_size = 1000*1000; // the max. size for uploading
    $multi_upload = new muli_files;
    $multi_upload->upload_dir = "uploads/"; // "files" is the folder for the uploaded files (you have to create this folder)
    $multi_upload->extensions = array(".png",".jpeg",".jpg"); // specify the allowed extensions here
    // $multi_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
    $multi_upload->max_length_filename = 1000; // change this value to fit your field length in your database (standard 100)
    $multi_upload->rename_file = false;
    $multi_upload->tmp_names_array = $_FILES['upload']['tmp_name'];
    $multi_upload->names_array = $_FILES['upload']['name'];
    $multi_upload->error_array = $_FILES['upload']['error'];
    //$multi_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
    //$multi_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
    //$new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
    $multi_upload->upload_multi_files();// new name is an additional filename information, use this to rename the uploaded file


}
else
{
    $imagename = "" ;
}

if($errorCount == "") {
//inserting data in to the data base
  $newModel = 'INSERT INTO `modeldetails`(`name`, `nicName`, `age`, `bust`, `height`, `hair`, `eyes`, `natio`, `descrip`, `stdService`, `otService`, `img1`, `Img2`, `Img3`, `Img4`) VALUES(\'' . $rName . "','" . $nicName . "','" . $age . "','" . $bust . "','" . $height . "','" . $hair . "','" . $eyes . "','" . $nAtio . "','" . $dEscrip . "','" . $std . "','" . $oth . "','" . $img1 . "','" .$img2. "','" .$img3. "','" .$img4. "')";

  $fireQuary = mysql_query($newModel);

//echo mysql_error();

    if ($fireQuary) {
        header("location:newmodel.php?msg=added");
        exit();
    } else {
        header("location:newmodel.php?msg=notadded");
        exit();
    }
}else{
    header("location:newmodel.php?error=".$errorCount);
}

form.php

<?php
/**
 * Created by PhpStorm.
 * User: SiNUX
 * Date: 9/13/14
 * Time: 1:07 PM
 */
session_start();
include_once('sessiocheck.php');
?>
<html>
<head>
    <title>Create a new model profile</title>
    <link rel="stylesheet" type="text/css" href="Scirpts/adminindex.css" />
</head>
<body style="background-image: none;">
<div id="index" style="margin:0 auto 0 auto; width:220px">
    <form enctype="multipart/form-data" action="newmodel_action.php" method="post" id="createuser">
        <fieldset>
            <legend>New Model Profile</legend>
            <?php if(isset($_GET["error"])) { ?>
                <div style="color: #ff0000; font-weight: bold;">
                    <?php echo $_GET["error"]; ?>
                </div>
            <?php } ?>
            <div class="margin">
                <label>Name</label><br />
                <input type="text" name="name" id="name" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Nick Name</label><br />
                <input type="text" name="nicname" id="nicname" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Age</label><br />
                <input type="text" name="age" id="age" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Bust</label><br />
                <input type="text" name="bust" id="bust" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Size</label><br />
                <input type="text" name="size" id="size" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Height</label><br />
                <input type="text" name="height" id="height" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Hair</label><br />
                <input type="text" name="hair" id="hair" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Eyes</label><br />
                <input type="text" name="eyes" id="eyes" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Nationality</label><br />
                <input type="text" name="natio" id="natio" maxlength="60" /><br />
            </div>
            <div class="margin">
                <label>Description</label><br />
                <textarea name="desc" id="desc" rows="8" cols="50"></textarea> <br />
            </div>
            <div class="margin">
              <fieldset>
                  <legend style="font-weight: normal; font-size: medium; text-align: left">Standard Services</legend>
                  <input type="checkbox" name="stdService[]" value="Sensual Massage" />
                  <label>Sensual Massage</label><br />
                  <input type="checkbox" name="stdService[]" value="French" />
                  <label>French</label><br />
                  <input type="checkbox" name="stdService[]" value="Foreplay" />
                  <lable>Foreplay</lable><br />
                  <input type="checkbox" name="stdService[]" value="GFE" />
                  <lable>GFE</lable><br />
                  <input type="checkbox" name="stdService[]" value="Toys" />
                  <lable>Toys</lable><br />
                  <input type="checkbox" name="stdService[]" value="Spanish" />
                  <lable>Spanish</lable><br />
                  <input type="checkbox" name="stdService[]" value="Swedish" />
                  <lable>Swedish</lable><br />
                  <input type="checkbox" name="stdService[]" value="Sex" />
                  <lable>Sex</lable><br />
                  <input type="checkbox" name="stdService[]" value="Ladies" />
                  <lable>Ladies</lable><br />
                  <input type="checkbox" name="stdService[]" value="Couples" />
                  <lable>Couples</lable><br />
                  <input type="checkbox" name="stdService[]" value="Bi" />
                  <lable>Bi</lable><br />
                  <input type="checkbox" name="stdService[]" value="Golden Showers" />
                  <lable>Golden Showers</lable><br />
                  <input type="checkbox" name="stdService[]" value="Private Strips" />
                  <lable>Private Strips</lable><br />
                  <input type="checkbox" name="stdService[]" value="Lap Dances" />
                  <lable>Lap Dances</lable><br />
                  <input type="checkbox" name="stdService[]" value="Topless Witressing" />
                  <lable>Topless Waitressing</lable><br />
                  <input type="checkbox" name="stdService[]" value="Fantasies" />
                  <lable>Fantasies</lable><br />
                  <input type="checkbox" name="stdService[]" value="Fetish" />
                  <lable>Fetish</lable><br />
                  <input type="checkbox" name="stdService[]" value="Dress Ups" />
                  <lable>Dress Ups</lable><br />
                  <input type="checkbox" name="stdService[]" value="Goes Twice" />
                  <lable>Goes Twice</lable><br />
                  <input type="checkbox" name="stdService[]" value="Dating" />
                  <lable>Dating</lable><br />
                  <!--<label>Other:</label>
                  <input type="text" name="stdService[]" />-->
              </fieldset>
            </div>
            <div class="margin">
                <fieldset>
                    <legend style="font-weight: normal; font-size: medium; text-align: left">Other Services</legend>
                    <input type="checkbox" name="othService[]" value="Sensual Massage" />
                    <label>Sensual Massage</label><br />
                    <input type="checkbox" name="othService[]" value="French" />
                    <label>French</label><br />
                    <input type="checkbox" name="othService[]" value="Foreplay" />
                    <lable>Foreplay</lable><br />
                    <input type="checkbox" name="othService[]" value="GFE" />
                    <lable>GFE</lable><br />
                    <input type="checkbox" name="othService[]" value="Toys" />
                    <lable>Toys</lable><br />
                    <input type="checkbox" name="othService[]" value="Spanish" />
                    <lable>Spanish</lable><br />
                    <input type="checkbox" name="othService[]" value="Swedish" />
                    <lable>Swedish</lable><br />
                    <input type="checkbox" name="othService[]" value="Sex" />
                    <lable>Sex</lable><br />
                    <input type="checkbox" name="othService[]" value="Ladies" />
                    <lable>Ladies</lable><br />
                    <input type="checkbox" name="othService[]" value="Couples" />
                    <lable>Couples</lable><br />
                    <input type="checkbox" name="othService[]" value="Bi" />
                    <lable>Bi</lable><br />
                    <input type="checkbox" name="othService[]" value="Golden Showers" />
                    <lable>Golden Showers</lable><br />
                    <input type="checkbox" name="othService[]" value="Private Strips" />
                    <lable>Private Strips</lable><br />
                    <input type="checkbox" name="othService[]" value="Lap Dances" />
                    <lable>Lap Dances</lable><br />
                    <input type="checkbox" name="othService[]" value="Topless Witressing" />
                    <lable>Topless Waitressing</lable><br />
                    <input type="checkbox" name="othService[]" value="Fantasies" />
                    <lable>Fantasies</lable><br />
                    <input type="checkbox" name="othService[]" value="Fetish" />
                    <lable>Fetish</lable><br />
                    <input type="checkbox" name="othService[]" value="Dress Ups" />
                    <lable>Dress Ups</lable><br />
                    <input type="checkbox" name="othService[]" value="Goes Twice" />
                    <lable>Goes Twice</lable><br />
                    <input type="checkbox" name="othService[]" value="Dating" />
                    <lable>Dating</lable><br />
                    <!-- <label>Other:</label>
                    <input type="text" name="othService[]" /> -->
                </fieldset>
            </div>
            <div class="margin">
                <input type="file" name="upload[]" />
                <input type="file" name="upload[]" />
                <input type="file" name="upload[]" />
                <input type="file" name="upload[]" />
            </div>
            <div class="margin">
                <input type="submit" name="submit" id="submit" value="Submit" />
                <input type="reset" name="reset" id="reset" value="Reset" />
            </div>
        </fieldset>
    </form>
</div>
<div style="background-color: chartreuse;">
    <?php if (isset($_REQUEST["msg"])){ echo $_REQUEST["msg"]; }?>

    <?php if(isset($_REQUEST["not"])) { echo $_REQUEST["msg"]; }?>
</div>
</body>
</html>