Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple image uploads
01-23-2005, 06:38 AM (This post was last modified: 01-23-2005 09:06 AM by Jackeh.)
Post: #3
RE: Multiple image uploads
Code:
<html>
<body>

<?php require (\'config.php\'); // data to connect to the DB ?>

<?php
    echo \"<form name=\\\"image_upload\\\" enctype=\\\"multipart/form-data\\\" method=\\\"post\\\" action=\\\"$PHP_SELF\\\">\\n\";

    $fields = 4; // number of upload fields

    for($x=0;$x<$fields;$x++){ // start of dynamic form (loop)
        echo \"<input name=\\\"image$x\\\" size=\\\"50\\\" type=\\\"file\\\" id=\\\"image$x\\\"><br>\\n\";

    } // end for loop to create 4 input fields
        echo \"<input type=\\\"submit\\\" name=\\\"submit\\\" value=\\\"Verstuur\\\">\\n\";
        echo \"</form>\";

if($_POST[\'submit\']) { // form has been submitted

        $num = \'0\';
        $sql = \"SELECT * from `test`\";
        $sql_result = mysql_query($sql) or die(\"Couldn\'t execute query.\");
        while ($row = mysql_fetch_array($sql_result)) {
          $id = $row[\"id\"];
if ($id > $num) {
$num == $id;
}
    }
        $sql = \"INSERT INTO test (id) values (\'$num\');
        $result = mysql_query($sql);

    for($x=0;$x<$fields;$x++){ // start for loop

    $file_name = $_FILES[\'image\'. $x][\'name\'];
    $uploads = \'upload\'; // directory to upload to
    $copy = copy($_FILES[\'image\'. $x][\'tmp_name\'],$uploads.\'/\'.$file_name);

        if($copy) { // check if successfuly copied
$file = \'image$x\';
            $sql = \"
       UPDATE `test`
       SET `$file` = \'$file_name\'
       WHERE `id` = \'$num\'
     \";
            $result = mysql_query($sql); // run SQL query against DB
            echo \"$file_name | uploaded successfuly!<br>\\n\";

        }else{
            echo \"$file_name | could not be uploaded!<br>\\n\";
        }

    } // end for loop

} // end of submit statement


?>

</body>
</html>

try something like that, i havnt tested it and its just off the top of my head really, but its a basic idea.. or something:\\
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Multiple image uploads - Jonathan - 01-23-2005, 05:32 AM
RE: Multiple image uploads - Pythong - 01-23-2005, 06:02 AM
RE: Multiple image uploads - Jackeh - 01-23-2005 06:38 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)