Tom1tk: Dateiupload: mehrere Dateien gleichzeitig

Hi Jungs (und Mädels!!)

ist es
a) überhaupt möglich mehrer Dateien gleichzeitig via Formular und PHP hochzuladen

b) wenn a=ja, wie?

Was mach ich da falsch:

Ganz einfach (nur zum Testen):

Aus nem Formular:
<input name="file" type="file">

if(copy($file,"uploads/$file_name"))
{
print "Juhu!";
}
}
else
{
print "Oh, oh. Das ging in die Hose...!";
}

So, und das gane könnt doch auch über nen Array gehen:

Aus nem Formular:
<input name="files[]" type="file">
<input name="files[]" type="file">
<input name="files[]" type="file">

foreach ($files as $file)
{
if(copy($file,"uploads/$file_name"))
{
print "Juhu!";
}
}
else
{
print "Oh, oh. Das ging in die Hose...!";
}
}//Ende foreach

Greets Tom1tk

  1. hi,

    a) überhaupt möglich mehrer Dateien gleichzeitig via Formular und PHP hochzuladen

    ja.

    b) wenn a=ja, wie?

    z.b. so, würde ich sagen:

    <input name="files[]" type="file">
    <input name="files[]" type="file">
    <input name="files[]" type="file">

    anschliessend machst du mal print_r($_FILES); um zu sehen, wie die daten ankommen.

    gruss,
    wahsaga

    1. Hi,

      anschliessend machst du mal print_r($_FILES); um zu sehen, wie die daten ankommen.

      Array ( [files] => Array ( [name] => Array ( [0] => test2.gif [1] => test3.gif [2] => test.gif ) [type] => Array ( [0] => image/gif [1] => image/gif [2] => image/gif ) [tmp_name] => Array ( [0] => /tmp/phpGLtC1g [1] => /tmp/phpg5ov4o [2] => /tmp/phpzuY6DS ) [error] => Array ( [0] => 0 [1] => 0 [2] => 0 ) [size] => Array ( [0] => 599 [1] => 62921 [2] => 2907 ) ) )

      OK. Was kann ich aus diesem Array sehen?
      Hinweis: Mit dem einen einzelnen Bild funktionierts wunderbar. Nur bei mehreren klappts net....

      Greets Tom1tk

      1. hi,

        OK. Was kann ich aus diesem Array sehen?

        _mehr_ erkennst du sicher, wenn du dir das ganze etwas übersichtlicher formatierst:

        Array (
             [files] => Array (
                  [name] => Array (
                       [0] => test2.gif
                       [1] => test3.gif
                       [2] => test.gif )
                  [type] => Array (
                       [0] => image/gif
                       [1] => image/gif
                       [2] => image/gif )
                  [tmp_name] => Array (
                       [0] => /tmp/phpGLtC1g
                       [1] => /tmp/phpg5ov4o
                       [2] => /tmp/phpzuY6DS )
                  [error] => Array (
                       [0] => 0
                       [1] => 0
                       [2] => 0 )
                  [size] => Array (
                       [0] => 599
                       [1] => 62921
                       [2] => 2907 ) ) )

        (bzw. in die quelltext-ansicht gehen, hätte wohl auch schon genügt.)

        gruss,
        wahsaga

        1. Autsch.

          Array (
               [files] => Array (
                    [name] => Array (
                         [0] => test2.gif
                         [1] => test3.gif
                         [2] => test.gif )
                    [type] => Array (
                         [0] => image/gif
                         [1] => image/gif
                         [2] => image/gif )
                    [tmp_name] => Array (
                         [0] => /tmp/phpGLtC1g
                         [1] => /tmp/phpg5ov4o
                         [2] => /tmp/phpzuY6DS )
                    [error] => Array (
                         [0] => 0
                         [1] => 0
                         [2] => 0 )
                    [size] => Array (
                         [0] => 599
                         [1] => 62921
                         [2] => 2907 ) ) )

          Und dann? Warum geht die foreach-Schleife nicht? Die sollte doch so gehen.... Oder muss man da jede $_FILE extra ansprechen ($_FILE[1] núsw...)?

          Greets Tom1tk