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 3 of 3
  1. #1
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts

    Multiple uploads with a single selection.

    Multiple uploads with a single selection. I modified a single upload script to allow for as many as twenty uploads in one batch, with one selection. Not all browsers support this so have a backup upload. Twenty uploads is the php default and the combined size can't exceed the maximum file size.
    PHP Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
    <script type="text/javascript">
    //Alerts to errors.
    window.onerror=function(msg, url, linenumber){var logerror='Error message: ' + msg + '. Url: ' + url + 'Line Number: ' + linenumber;alert(logerror);return false}
    </script>
    <body >
    <?php
    //include("./colors.php");
    if(isset($_POST['MAX_FILE_SIZE'])){
    $newdir $_POST['newdir'];
    $dir './Uploads/';
    $upload $dir.$newdir;
    if (!
    file_exists($upload)) {mkdir ($upload); chmod($upload0777); }
    $uploaddir $upload."/";
    $isAllowed = array("image/jpeg","image/png","image/gif","image/bmp","application/octet-stream");
    for ( 
    $f $f count($_FILES['userfile']['tmp_name']) ; $f++ )
    {    
    $ext =  basename($_FILES['userfile']['type'][$f]);
        if  (
    move_uploaded_file($_FILES['userfile']['tmp_name'][$f], $uploaddir.$_FILES['userfile']['name'][$f])) {
        if  (
    in_array $_FILES['userfile']['type'][$f] , $isAllowed )) echo "File ".$_FILES['userfile']['name'][$f]." is valid, and was successfully uploaded.\n<br>";}
        if  (!
    in_array $_FILES['userfile']['type'][$f] , $isAllowed )){echo "File ".$_FILES['userfile']['name'][$f]." was not an allowed type.\n<br>Allowed types are jpeg, png, gif and bmp\n<br>";}
        
    $img[$f] = $uploaddir.$_FILES['userfile']['name'][$f];
        print 
    "<img src=\"".$img[$f]."\"><br>";
    }}
    echo 
    '<pre>';
    print_r($_FILES);
    echo 
    "<br>";
    print 
    "</pre>";
    ?>
    <!-- The data encoding type, enctype, MUST be specified as below -->
    <form enctype="multipart/form-data"  action="index.php" method="POST">
        Make a new folder: <input type="text" name="newdir" />
        <!-- MAX_FILE_SIZE must precede the file input field -->
        <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
        <!-- Name of input element determines name in $_FILES array -->
        Send this file: <input name='userfile[]' type='file'  multiple=20 />
    <input type="submit" value="Send File" />
    </form> 
    <br>
    <a href="./download.php">Download</a>
    <br><br>
    </body>
    </html>

    //  And the download.php used for testing downloads.

    <?php
    $add 
    time();
    header('Content-type: image/jpeg');
    header('Content-Disposition: attachment; filename="output-'.$add.'.jpg"');
    readfile('./Uploads/Drew/drew von kern new 8.JPG');
    ?>
    Last edited by DrDOS; 06-28-2012 at 04:10 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,866
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    include("./colors.php");
    Where's that?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    Quote Originally Posted by abduraooft View Post
    Where's that?
    So omit that line, and any other superfluous code. Like I don't have to modify the code of people who upload other example files! Jeesh! BTW colors.php writes a select box with all the 'named' colors with their # values. I could upload that too if you want it.


  •  

    Posting Permissions

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