Antonie Potgieter
By: a guest | Nov 20th, 2007 | Syntax:
PHP | Size: 1.61 KB | Hits: 128 | Expires: Never
<?php
//start a PHP session.
class Upload {
//upload directory.
//make sure it exists
//chmod it to 0777 to be writable
var $upload_dir = "uploads/";
//the name of the file.
var $name = '';
//TMP name of the file on server.
var $tmp_name = '';
//the size of the file.
//this is measured in bytes
var $size = '';
//the mime type of the file.
//ex. image/png
var $type = '';
//number of files uploaded so far.
var $count = 1;
function Upload
($file = array()) {
//make sure that the file data is not empty.
//loop the file array
foreach ($file as $key => $val) {
$this -> {$key} = $val;
}
//execute the uploading method.
$this -> upload_file();
}
}
function upload_file() {
//make sure the the file has been uploaded
//make sure that the file can be moved to the "upload_dir"
//increment the file count.
$newcount = (!isset($_SESSION['filecount'])) ?
$this -> count : ($_SESSION['filecount'] + 1
);
$_SESSION['files'][$newcount]['filename'] = $this -> name;
$_SESSION['files'][$newcount]['filesize'] = $this -> size;
$_SESSION['files'][$newcount]['filetype'] = $this -> type;
} else {
//file could not be moved
return false;
}
} else {
//file was not uploaded
return false;
}
}
}
//get all the posted file data
$file = $_FILES['Filedata'];
//initialize the Upload class.
$upload = new Upload($file);
?>