note 56290 added to features.file-upload

From: Date: Mon, 29 Aug 2005 21:53:12 +0000
Subject: note 56290 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-94356@lists.php.net to get a copy of this message
Here is something I put together that will dynamically generate up to 5 file inputs and then on submission generate a table with all the file information on each field. Handle for anyone learning how to use this with file uploads and wants to see things visually, also is set up nicely to have it as an attach script for emails or uploading to a server. <? if(isset($_POST['attach_files'])) { echo "<table width=\"600\" border=\"1\"> <tr> <td>Upload #</td> <td>File Name</td> <td>Temp Name</td> <td>File Size</td> <td>File Type</td> <td>Error</td> </tr>"; $counter = 0; foreach($_FILES as $key => $value) { $counter++; echo "<tr> <td>$counter</td> <td>" . $_FILES[$key]['name'] . "</td> <td>" . $_FILES[$key]['tmp_name'] . "</td> <td>" . $_FILES[$key]['size'] . "</td> <td>" . $_FILES[$key]['type'] . "</td> <td>" . $_FILES[$key]['error'] . "</td> </tr>"; } echo "</table>"; } ?> <form name="att_files" method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <select name="amt_upload"><? for($i=1; $i<6; $i++) { echo "<option value=\"$i\" onMouseDown=\"javascript:attach_amount($i);\">$i</option>"; } ?></select><br/> <div id="file_container"> <input type="file" name="file1" /><br/> </div> <input type="submit" name="attach_files" value="Attach" /> </form> <script language="Javascript" type="text/javascript"> <!-- function attach_amount(amt) { var loop_amt = amt+1; var sHTML = ""; for(var i=1; i<loop_amt; i++) { var filename = "file"+i; sHTML += "<input type=\"file\" name=\"" + filename + "\" /><br/>"; } file_container.innerHTML = sHTML; } --> </script> ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56290 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56290&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56290&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56290&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56290&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56290&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56290&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56290&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94356) next »