Recent Posts
Bash | 4 sec ago
None | 14 sec ago
AppleScript | 1 min ago
None | 1 min ago
None | 1 min ago
C | 1 min ago
None | 2 min ago
None | 2 min ago
None | 2 min ago
None | 2 min ago
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By Antonie Potgieter on the 20th of Nov 2007 04:19:31 PM
Download |
Raw |
Embed |
Report
<?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);
?>
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post