Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post

    cant get in the files array

    this works
    Code:
    <?php copy ($_FILES['f']['tmp_name'], $_FILES['f']['name']); ?>
    but when trying to access the files array for multiple uploads, i'm stumped. i've tried each of the following with inputs named f and f[]
    Code:
    foreach($_FILES['f'] as $file) copy($file['tmp_name'], $file['name']);
    foreach($_FILES as $file) copy($file['f']['tmp_name'], $file['f']['name']);
    foreach($_FILES['f']['tmp_name'] as $file) copy($file, $_FILES['f']['name']);
    any insight would be greatly appreciated.

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually the first one should work.

    PHP Code:
    <input type="file" name="files[]">
    <
    input type="file" name="files[]">
    <
    input type="file" name="files[]">

    foreach (
    $_FILES['files'] as $file)
    {
      
    copy ($file['tmp_name'], $file['name']);


  • #3
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post
    hi aaron, thanks for taking the time to reply.

    i'm still getting the following error returned
    Code:
    Warning: Invalid argument supplied for foreach()
    i added line break and curlies just in case, still no good. permissions are set properly, and i'm able to upload fine to the same directory - if i just take the foreach bit out the script works fine so i don't suppose it could be a conflict with php installations - i'm stumped. perhaps i'm missing something simple; complete test follows:
    Code:
    <html><body>
    <form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
    <input type="file" name="file[]" />
    <input type="file" name="file[]" />
    <input type="file" name="file[]" />
    <input type="file" name="file[]" />
    <input type="submit" name="submit" />
    <?php if(isset($submit)) foreach($_FILES['file'] as $file) copy($file['tmp_name'], $file['name']); ?>
    </form>
    </body>
    </html>
    that doesnt work, in the same dir this does
    Code:
    <html><body>
    <form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
    <input type="file" name="singlefile" />
    <input type="submit" name="submit" />
    <?php if(isset($submit)) copy($_FILES['singlefile']['tmp_name'], $_FILES['singlefile']['name']); ?>
    </form>
    </body>
    </html>

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Try using curly braces aswell in your code {}

    PHP Code:
    <?php 
    if(isset($_POST['submit'])){
       foreach(
    $_FILES['file'] as $file){ 
          
    copy($file['tmp_name'], $file['name']);
       }
    }
    ?>

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post
    i added line break and curlies just in case
    i tried switching it up, and it wasnt any help. does that script work for you nightfire? am i to assume the problem is with the host and note the code? thanks for your input.

  • #6
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post
    wierd - not the host, i tried same code on two other servers - again the single upload works fine, but can't get into the files array - not even for an echo output. curiously, this does work
    Code:
    <?php for ($i=0;$i<4;$i++) copy($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]); ?>
    i'm still mystified, but at least operational.


  •  

    Posting Permissions

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