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

<form action="<?php href('clientarea/documents/add-save/')?>" method="post" enctype="multipart/form-data">
				<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 } ?>

			<dd><input type="text" class="text" name="title" value="" /></dd>
			<dt>*Upload File</dt>
			<dd><input type="file" name="document_file" /></dd>
			<dd><textarea name="description" rows="8" cols="40"></textarea></dd>
		<div class="break"></div>
		<p style="margin-top: 20px;"><input type="submit" value="Add >" /></p>


You might want to look into a Flash or jQuery uploader. Those will let you upload multiple files without killing yourself. :slight_smile:

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…

<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" />

You’ll end up with $_FILES being…

    [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

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. :slight_smile:

execution_time may need to be increased.

Also make sure you don’t rely on the MIME type data to determine the file type, as this can easily be forged.

At this page Multiple upload files there is a tutorial and a script for uploading multiple pages.
Maybe it helps you.