Hi all

Having a bit of a problem uploading files. The tutorials I have looked at all seem to be a little too complex for my needs.

All I want to do is have a user, via a form possibly, upload upto 5 photos or graphics files to a directory, which I set in the script, on my server.

I dont need it to be registered in a database or a flat file, just purely upload to the given directory.

A form with say, 5 file upload boxes with the browse button would suffice. Only thing is they only need to upoad as many as they want, could be 1 file could b3 files or could be 5.

Has anyone come across a script that does this or can anyone point me inthe direction of a tutorial.

Thanks you all

    HTML arrays
    http://us2.php.net/manual/en/features.file-upload.php

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

    PHP.NET

      Wow,

      So quick and works like a dream, exactly what i wanted, thank you so much.

      All I need to do now is sort out a success page and how to incorporate it into you script and jobs a good one

      Thanks again

        Whoops

        Just noticed an error

        When the php file first loads on the screen there are the three upload fields and the submit button and underneath them there is this error

        Warning: Invalid argument supplied for foreach() in /home/sites/grap.co.uk/public_html/testing/file.php on line 20

        if you proceed and upload files then the page reloads and that error has gobe?

        Any ideas

          It's trying to access the $_FILES array before anything's been uploaded but it's empty.

          Ideally you'd either change the script so the files get saved to another page or use:

          if (!empty($_FILES))
          {
          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");
             }
          }
          } 
          
            Write a Reply...