#comment filename ->class.upload.php
<?php
class uploadObject{
private $allowedfiles;
private $max_filesize;
private $upload_path;
private $filename;
private $ext;
private $parameter_to_use;
function __construct($allowedfiles, $max_filesize, $upload_path, $filename,$parameter_to_use) {
$this->allowedfiles = $allowedfiles;
$this->max_filesize = $max_filesize;
$this->upload_path = $upload_path;
$this->filename = $filename;
$this->ext = substr($filename, strpos($filename,’.'), strlen($filename)-1);
$this->parameter_to_use = $parameter_to_use;
}
function upload(){
# Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($this->ext,$this->allowedfiles))
die(‘The file you attempted to upload is not allowed.’);
# Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $this->max_filesize)
die(‘The file you attempted to upload is too large.’);
# Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($this->upload_path))
die(‘You cannot upload to the specified directory, please CHMOD it to 777 on linux or check permission on Windows.’);
$this->filename = $this->parameter_to_use.”.jpeg”; # Renaming our photo to an id
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$this->upload_path . $this->filename))
{
$img_path = $this->upload_path. $this->filename;
return $img_path;
}
else{
echo ‘There was an error during the file upload. Please try again.’;
exit(0);
}
}//upload
}//class
?>