SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Brackets "[ ]" with multiple input/upload boxes, $_FILES array

    How can I put UserFile1 into array brackets (like so: UserFile[1]) below and have it output on the OutputPage.php page? Also, on the OutputPage.php I need to put $n into array brackets like so: UserFile[$n].

    The script works ok just appending numerals to the end of the name for the input/upload box and appending $n to the end of UserFile on the OutputPage.php. Since the uploaded files are an array it somehow seems like it might be best to include the numerals in array brackets.

    Would it be better to somehow use array brackets in the InputPage.php and OutputPage.php scripts below? Or, will it not work because inserting the array brackets like below is not supposed to work?

    PHP Code:

    // This one (i.e. InputPage.php and OutputPage.php) works.
    // This one outputs the file type, file name, sile size, and temp name:
    // InputPage.php
    <form enctype="multipart/form-data" action="UOutputPage.php" method="POST">
    <
    input name="UserFile1" type="file">
    <
    input name="UserFile2" type="file">
    <
    input name="UserFile3" type="file">
    <
    input name="UserFile4" type="file">
    </
    form>

    // OutputPage.php
    for ($n 1$n <= 4$n++){
    $FileType $_FILES["UserFile$n"]["type"];
    $FileName $_FILES["UserFile$n"]["name"];
    $FileSize $_FILES["UserFile$n"]["size"];
    $TempName $_FILES["UserFile$n"]["tmp_name"];
    $FileError $_FILES["UserFile$n"]["error"];

    // This InputPage/OutputPage.php combination does not work.
    // But if I put the array brackets ("[ ]") around the UserFile and the $n like so:
    // InputPage.php
    <form enctype="multipart/form-data" action="UOutputPage.php" method="POST">
    <
    input name="UserFile[1]" type="file">
    <
    input name="UserFile[2]" type="file">
    <
    input name="UserFile[3]" type="file">
    <
    input name="UserFile[4]" type="file">
    </
    form>

    // OutputPage.php
    for ($n 1$n <= 4$n++){
    $FileType $_FILES["UserFile[$n]"]["type"];
    $FileName $_FILES["UserFile[$n]"]["name"];
    $FileSize $_FILES["UserFile[$n]"]["size"];
    $TempName $_FILES["UserFile[$n]"]["tmp_name"];
    $FileError $_FILES["UserFile[$n]"]["error"];

    // it won't work.
    // 
    Thanks.
    .

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $_FILES['UserFile'][$n]['type or name or size']

  3. #3
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for responding to my problem.

    I just looked in the PHP Manual. It tells about uploading multiple files using arrays in Chapter 38. I should have looked harder there first before posting.

    It's been about a year since I've used PHP much. I remember about a year ago the PHP Manual did not have any information (or I overlooked it - which is more likely) about uploading multiple files.

    I've let myself get a little bit rusty.

    Thanks again for the help.
    .


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •