Re: Multiple file upload

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 11, 2009 at 12:09 PM, Matthew Croud <matt@xxxxxxxxxxxxxxxxxx>wrote:

> Dear lords of PHP,
>
> I have a working image upload script that meets all my needs,
> My question is I need to upload multiple images using the same form,
>
> This is the PHP part I have so far, largely taken from a book:
> _________________________________________________________
>
> $file_dir = "/public_html/uploads";
> foreach($_FILES as $file_name => $file_array) {
>        echo "path: ".$file_array["tmp_name"]."<br/>\n";
>        echo "name: ".$file_array["name"]."<br/>\n";
>
>        $UploadName = $file_array["name"];
>
>        if (is_uploaded_file($file_array["tmp_name"])) {
>                move_uploaded_file($file_array["tmp_name"],
> "$file_dir/".$file_array["name"]) or die ("Couldn't copy");
>                echo "file was moved!<br/>";
>        }
> }
> _________________________________________________________
>
> Lets say the HTML from that sends data to this script has 3 upload forms
> that get send to $_FILES, would I access the data by modifying the following
> line from the above example:
> ...
> foreach($_FILES[' UPLOADIMAGE1 '] as $file_name => $file_array) {
> ...
>
> ...
> foreach($_FILES[' UPLOADIMAGE2 '] as $file_name => $file_array) {
> ...
>
> ...
> foreach($_FILES[' UPLOADIMAGE3 '] as $file_name => $file_array) {
> ...
>
> Thanks for reading!
> Matt Cheezoid
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Your foreach does exactly what you are asking.

foreach($_FILES as $file_name => $file_array)

The keys in $_FILES are the <input type="file" /> in your form.
If you have 3 files... then count( $_FILES ) should be 3


-- 
Martin Scotta

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux