Search
| PHP code to upload and delete images |
|
|
|
| Programming - PHP |
| Monday, 06 July 2009 07:57 |
|
/*All images are uploaded into a directory images. You can view the images and delete it*/
<html> <body> <form action="<?php $_SERVER[PHP_SELF];?>" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> <?php $thumbs_dir = "./images/"; $dir = opendir($thumbs_dir); $action=$_GET[action]; $file=$_GET[imageid]; if ($action == "delete") { unlink($thumbs_dir.$file); } if ($_POST['submit']) { $_FILES['uploaded_image']['tmp_name']; if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } move_uploaded_file($_FILES["file"]["tmp_name"], "../images/" . $_FILES["file"]["name"]); } while ($file = readdir($dir)) { if ($file != "." && $file != ".." ) { echo "<tr><td class='divider'><img src='$thumbs_dir$file' border='0' /></td></tr> <tr> <td class='divider'>$file</td><td class='divider'> <a href="/programming/php?imageid=%24file&action=delete">» Delete</a></td></tr>"; } } ?> |
| Last Updated on Friday, 24 July 2009 22:31 |




