phprockers-logo

Multiple File uploads in PHP

<?php
    $con = mysql_connection() or(mysql_error();

    mysql_db_select("phprockers", $con) or mysql_error();
?>
<form method="POST" action="" enctype="multipart/form-data">

    Images 1: <input type=file name='images1' ><br>
    Images 2: <input type=file name='images2' ><br>
    Images 3: <input type=file name='images3' ><br>
    <input type="submit" name="submit" value="Submit" />

</form>
<?php
    if($_POST['submit']!="" ) {
        $upload_directory = '/upload/';
        for ($i = 1; $i <= count($_FILES); $i++) {

            $path = $_FILES['images'.$i]['name'];
            move_uploaded_file($_FILES['images'.$i]['tmp_name'], $upload_directory . basename($_FILES['images'.$i]['name']));
            $query="INSERT INTO browsefile (id,path) values('$path')";
            mysql_query( $query );

        }
    }
?>

1 comment: