note 56290 deleted from features.file-upload by mazzanet
| From: | mazzanet@php.net | Date: | Tue, 30 Aug 2005 10:18:30 +0000 |
| Subject: | note 56290 deleted from features.file-upload by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-94377@lists.php.net to get a copy of this message | ||
Note Submitter: running_bases at yahoo dot com
----
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>