note 103654 deleted from features.file-upload by danbrown
| From: | danbrown@php.net | Date: | Tue, 26 Apr 2011 16:14:37 +0000 |
| Subject: | note 103654 deleted from features.file-upload by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179168@lists.php.net to get a copy of this message | ||
Note Submitter: spaceemotion
----
I wrote a little upload Manager, inspired by Marcus' post. I hope it helps ;) (Sorry for
HTML-tags)
<html><head><title>Simple Upload Manager</title></head><body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data">
<input type="file" name="ufile" />
<input type="submit" value="Upload" />
<input type="hidden" name="upload" value="1" />
</form>
<?php
$uploaddir = "files/"; // upload directory
//Enable this if you want to display PHP-Warnings
ini_set('display_errors', 0 );
if($_POST['upload'] == 1) {
$tempname = $_FILES['ufile']['tmp_name'];
$name = $_FILES['ufile']['name'];
$type = mime_content_type($tempname);
$size = $_FILES['ufile']['size'];
$path = $uploaddir.$name;
copy($tempname, $path);
?>
<table border="1" width="100%">
<colgroup><col width="*"><col width="20%"><col
width="20%"></colgroup>
<thead>
<tr><th align="Center" colspan="3"
bgcolor="green"><font color="white">Upload
Successful</font></th></tr>
<tr><th align="center"><b>Name</b></th><th
align="center"><b>Size</b></th><th
align="center"><b>MIME-Type</b></th></tr>
</thead>
<tbody><tr><td align="left"><?php echo $name;
?></td><td align="left"><?php echo $size; ?></td><td
align="left"><?php echo $type; ?></td></tr></tbody>
</table><?php
} elseif($_GET['del'] != '') {
if (!unlink($uploaddir.$_GET['del']))echo '<font
color="#c00000">Error Deleting File</font>';
else echo '<font color="green">File deleted</font>';
}?>
<table border="1" width="100%">
<colgroup><col width="*"><col width="20%"><col
width="20%"></colgroup>
<thead>
<tr><th align="Center" colspan="4"
bgcolor="black"><font color="white">Uploaded
Files</font></th></tr>
<tr><th align="center"><b>Name</b></th><th
align="center"><b>Size</b></th><th
align="center"><b>MIME-Type</b></th><th
align="center"><b> </b></th></tr>
</thead>
<tbody>
<?php
if ($handle = opendir($uploaddir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo '<tr';if($name == $file) echo ' class="current"'; echo
'>';
echo '<td align="left">'.$file.' (<a
href="'.$uploaddir.$file.'">'.$uploaddir.$file.'</a>)</td>';
echo '<td
align="left">'.filesize($uploaddir.$file).'</td>';
echo '<td
align="left">'.mime_content_type($uploaddir.$file).'</td>';
echo '<td align="center"><a
href="'.$_SERVER['PHP_SELF'].'?del='.$file.'">Del</a></td>';
echo '</tr>';
}
}
closedir($handle);
}
?>
</tbody>
</table>
</body></html>