Multiple Image Upload

Hey,

I need to upload “up to 4” images. The user has a choice of how many images they want to upload but no more than 4. Currently i have the following code:

Items.class.php


    public function insertItems($category){
		
        $sql = "INSERT INTO tbl_items
            (catID, name, description, price, colours, image_1, image_2, image_3, image_4, google, date_added, deleted) VALUES
            (
            '".mysql_real_escape_string($_POST['catID'])."',
            '".mysql_real_escape_string($_POST['name'])."',
            '".mysql_real_escape_string($_POST['description'])."',
            '".mysql_real_escape_string($_POST['price'])."',
            '".mysql_real_escape_string($_POST['colours'])."',
            '".mysql_real_escape_string($_FILES['image1']['name'])."',
            '".mysql_real_escape_string($_FILES['image2']['name'])."',
            '".mysql_real_escape_string($_FILES['image3']['name'])."',
            '".mysql_real_escape_string($_FILES['image4']['name'])."',
            '".mysql_real_escape_string($_POST['google'])."',
            now(),
            0
            )";
        $result = mysql_query($sql);
        return "Successfully added item";
    }

Then i have 4 image upload files on a page like so:


<input type="file" name="image1" id="image1" value=""/>
<input type="file" name="image2" id="image2" value=""/>
<input type="file" name="image3" id="image3" value=""/>
<input type="file" name="image4" id="image4" value=""/>

Once i hit submit i would do something like this:


    $target_path = "../productimages/";
    $target_path = $target_path . basename( $_FILES['image']['name']);

    if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['image']['name']).
        " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }

        $message = Items::updateItem();
        header('location: manage-products.php');

But this would only be for one image, and i am SURE that there is a better way of doing this rather than repeating these lines 4 times for each image upload…?

How can i make this work? Can someone help?

Thanks

I was thinking of an array of image uploads? But i don’t know if this is the right way to go?

How can i do this?

Can someone please offer anyadvice as to how I need to to go about doing this? Thanks