Jump to content

Multiple upload with db support


feri_soft

Recommended Posts

Hi,
I need a multiple file upload script that have for example 5 fields and can only allow gif and jpg to be uploaded.Another very important thing is to have db support so the data of the files can be stored in db data such as... filename,size and file_id...

I created a solution for this but only for single file upload...but for multiple!?

Thank you!


p.s

I found this on the web but i cant figure it out how to create a db support for it:
[code]<?php
/* Handle multiple file upload easily */
/* by Ronny Haryanto <giant@canada.com> */
/* February-ish 1999 */

/* Use it however you want. I'm not responsible for what you do with it. */

/* how many upload slots? */
define("UPLOAD_SLOTS", 5);

/* where to move the uploaded file(s) to? */
define("INCOMING", "/home/ronny/incoming/");

if($REQUEST_METHOD!="POST")
{
        /* generate form */
        echo "<form enctype=\"multipart/form-data\" method=post>\n";
        for($i=1; $i<=UPLOAD_SLOTS; $i++)
        {
                echo "<input type=file name=infile$i><br>\n";
        }
        echo "<input type=submit value=upload></form>\n";
}
else
{
        /* handle uploads */
        $noinput = true;
        for($i=1; $noinput && ($i<=UPLOAD_SLOTS); $i++)
        {
                if(${"infile".$i}!="none") $noinput=false;
        }
        if($noinput)
        {
                echo "error uploading. create 150MB coredump instead?";
                exit();
        }
        for($i=1; $i<=UPLOAD_SLOTS; $i++)
        {
                if(${"infile".$i}!="none" &&
                copy(${"infile".$i}, INCOMING.${"infile".$i."_name"}) &&
                unlink(${"infile".$i}))
                {
                        echo ${"infile".$i."_name"}." uploaded<br>";
                }
        }
} /* else */
?>[/code]
Link to comment
Share on other sites

Ok i found this but how to create db support for it:

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>

<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
  if ($error == UPLOAD_ERR_OK) {
      $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
      $name = $_FILES["pictures"]["name"][$key];
      move_uploaded_file($tmp_name, "data/$name");
  }
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.