Jump to content


Photo

Multiple upload with db support


  • Please log in to reply
3 replies to this topic

#1 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 31 August 2006 - 04:13 PM

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:
<?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 */
?>


#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 31 August 2006 - 04:29 PM

on the form, have
<input type='file' name='infile[]' />

This makes them an array

then loop through the array
Tell me the problem, I will try tell you the solution

#3 jpratt

jpratt
  • Members
  • PipPipPip
  • Advanced Member
  • 144 posts

Posted 31 August 2006 - 04:31 PM

go to:

http://us3.php.net/m...file-upload.php

has an example of uploading an array of files.

#4 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 01 September 2006 - 06:22 AM

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");
  }
}
?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users