Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I am struggling to get this code to work. What I am trying to do is upload a maximum of 5 image files at once.

    When I submit the form I do get the "File has been stored in your directory" but I go into that directory and there are no files there..

    PHP Code:
    <?php

    if ($_POST['submit'] == "Upload") {

    for(
    $i=0;$i<count($_FILES['files']['name']);$i++)
    {
      
    $filename $_FILES['files']['name'][$i];
     
    move_uploaded_file($filename"images/" $filename);
    echo 
    "File has been stored in your uploads directory."
    }
    }
    and my form looks like
    Code:
    <form name="uploadfiles" action="<?php echo $PHP_SELF;?>" method="post" enctype="multipart/form-data">
    
    <input type="file" name="files[]" /><br />
    <input type="file" name="files[]" /><br />
    <input type="file" name="files[]" /><br />
    <input type="file" name="files[]" /><br />
    <input type="file" name="files[]" /><br /><br />
    <input type="submit" name="submit" value="Upload" />
    
    </form>
    Any ideas?

    * edit

    I am now getting this error message

    Warning: move_uploaded_file(images/bush.jpg): failed to open stream: Permission denied in /home/upload/public_html/admin.php on line 24

    Warning: move_uploaded_file(): Unable to move '/tmp/phpTyNAOh' to 'images/bush.jpg' in /home/upload/public_html/admin.php on line 24
    My revised php is
    PHP Code:
    if ($_POST['submit'] == "Upload") {

    for(
    $i=0;$i<count($_FILES['files']['name']);$i++)
    {
     
    move_uploaded_file($_FILES['files']['tmp_name'][$i], "images/" .$_FILES['files']['name'][$i]);
    echo 
    "File has been stored in your uploads directory."
    }


  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, you're not testing to see whether move_uploaded_file is returning true or false. move_uploaded_file will return false if it fails, so you might want to look at that. Also, does the webserver user have write access to the directory?

    Lastly, when you create files, make sure you set permissions right on them, since sometimes PHP will create them with strange permissions that, by default, won't allow you to delete them. I was faced with this problem earlier and had to run a PHP script to fix all the permissions. That was fun :-P

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Shadowfiend: I thank thee

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    What was the problem, in the end?

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Yeah thats more helpful...

    I gave the folder a +w mode.

    I also added
    PHP Code:
    if($_FILES['files']['name'][$i] != "") {...} 
    Because before it was "trying" to upload all form values even if I only tried to upload one.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:22 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com