SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: File upload

  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File upload

    I have a website that I have to upload items to on a regular basis and I was trying to figure out how to make it to where I can add more than 1 file at a time to the site. I now use the below code to get uploads to work. I would like to make it to where I can add say 5-10 files at once. I tried a few changes but anything i did seems to break the script, here is the script any help would be greatly appreciated
    Code:
    <form action="<?php href('clientarea/documents/add-save/')?>" method="post" enctype="multipart/form-data">
    		<dl>
    			<dt>*User</dt>
    			<dd>
    				<select name="clientarea_user_id">
    					<option value=""></option>
    					<?php foreach($users as $u) { ?>
    					<option value="<?php echo $u['id'] ?>"><?php echo "{$u['first_name']} {$u['middle_initial']} {$u['last_name']}" ?></option>
    					<?php } ?>
    				</select>
    			</dd>
    
    			<dt>*Title</dt>
    			<dd><input type="text" class="text" name="title" value="" /></dd>
    			
    			<dt>*Upload File</dt>
    			<dd><input type="file" name="document_file" /></dd>
    		
    			<dt>Description</dt>
    			<dd><textarea name="description" rows="8" cols="40"></textarea></dd>
    		</dl>
    		<div class="break"></div>
    		<p style="margin-top: 20px;"><input type="submit" value="Add &gt;" /></p>
    	</form>

  2. #2
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to look into a Flash or jQuery uploader. Those will let you upload multiple files without killing yourself.

  3. #3
    SitePoint Zealot cholmon's Avatar
    Join Date
    Mar 2004
    Location
    SC
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can have multiple file fields, just name them as such by appending "[]"...just be aware that $_FILES ends up structured in a way that you might not expect. If you do this...

    HTML Code:
    <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="img[]" />
        <input type="file" name="img[]" />
        <input type="file" name="img[]" />
        <input type="submit" />
    </form>
    You'll end up with $_FILES being...
    Code:
    Array
    (
        [name] => Array
            (
                [0] => me.jpg
                [1] => you.jpg
                [2] => us.jpg
            )
    
        [type] => Array
            (
                [0] => image/jpeg
                [1] => image/jpeg
                [2] => image/jpeg
            )
    
        [tmp_name] => Array
            (
                [0] => /tmp/phpXyZpdq
                [1] => /tmp/phpoMGwTf
                [2] => /tmp/phpNvmbBL
            )
    
        [error] => Array
            (
                [0] => 0
                [1] => 0
                [2] => 0
            )
    
        [size] => Array
            (
                [0] => 1234
                [1] => 5678
                [2] => 9101
            )
    )
    ...so you gotta loop appropriately
    Drew C King: PHP Developer
    <?= $short_tags++ ?>

  4. #4
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Keep in mind that you will need to set your php.ini configuration accordingly using that method, specifically upload_max_filesize and post_max_size. upload_max_filesize being the sum of all files being uploaded, and post_max_size being the sum of upload_max_filesize and the rest of the form's content. If I remember that correctly.

  5. #5
    SitePoint Enthusiast praveenkv1988's Avatar
    Join Date
    May 2011
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    execution_time may need to be increased.

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also make sure you don't rely on the MIME type data to determine the file type, as this can easily be forged.

  7. #7
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hy,
    At this page Multiple upload files there is a tutorial and a script for uploading multiple pages.
    Maybe it helps you.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners


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
  •