PHP Classes

File: imageupload.php

Recommend this page to a friend!
  Classes of Er. Rochak Chauhan   AJAX File Uploader   imageupload.php   Download  
File: imageupload.php
Role: Auxiliary script
Content type: text/plain
Description: Uploads image
Class: AJAX File Uploader
Browse files uploaded without page reloading
Author: By
Last change: Security Patch Added
Date: 15 years ago
Size: 1,289 bytes


Class file image Download
 * This file uploads a file in the back end, without refreshing the page

if (isset(
$_POST['id'])) {
//$uploadFile=$_GET['dirname']."/".$_FILES[$_POST['id']]['name']; for security reasons, hardcode the name of the directrory.

is_dir($_GET['dirname'])) {
'<script> alert("Failed to find the final upload directory: $dirName);</script>';
    if (!
copy($_FILES[$_POST['id']]['tmp_name'], $dirName.'/'.md5($_FILES[$_POST['id']]['name'].".demo"))) {
'<script> alert("Failed to upload file");</script>';
else {
// for secority reason either remove the extentions or rectrict uploaded not to upload / run scripts like file.php else they can misuse the disk space
    //$uploadFile=$_GET['dirname']."/".$_GET['filename']; // removed for security reasons (happend with my demo )
    if (
file_exists($uploadFile)) {
"File uploaded. <a href='$uploadFile'>Open File</a> &nbsp;&nbsp;&nbsp; <a href='deletefile.php?filename=".$uploadFile."'>Delete File</a>";
    else {
"<img src='loading.gif' alt='loading...' />";