class d_upload {
var $formfields;
var $errorback;
var $whichfields;
var $sendfieldinfoback;
var $ads_upload_dir = "../pdfs/";
var $ads_upload_max_filesize = 10240000;
##########
function upload_add_ad($thefiletoupload,$upload_filesize,$upload_file_type,$temp_file_upload_name,$file_upload_error){
$uploadDir = $this->ads_upload_dir.$_POST['event']."/";
if ($file_upload_error != 0){
if ($file_upload_error == 1){
$this->errorback = 1;
$this->whichfields .= "filesize,";
}
if ($file_upload_error == 2){
$this->errorback = 1;
$this->whichfields .= "filesize,";
}
if ($file_upload_error == 3){
$this->errorback = 1;
$this->whichfields .= "partialupload,";
}
if ($file_upload_error == 4){
$this->errorback = 1;
$this->whichfields .= "nofileuploaded,";
}
} else {
if ($upload_filesize == 0 || $upload_filesize > $this->ads_upload_max_filesize){
$this->errorback = 1;
$this->whichfields .= "filesize,";
}
if (! preg_match("/^application\/x-msdownload|application\/pdf$/i",$upload_file_type)){
$this->errorback = 1;
$this->whichfields .= "wrongformat,";
}
}
$firstfilebit = preg_replace("/^(.+)\.pdf$/i","\\1",$thefiletoupload);
$knockout = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*");
$newname = str_replace($knockout, "_", $firstfilebit);
$newname = preg_replace("/_{2,}/","_",$newname);
$newfilename = $newname.".pdf";
if (! $this->errorback){
$newrandomfilenamewithpath = $uploadDir . $newfilename;
@move_uploaded_file($temp_file_upload_name, $newrandomfilenamewithpath);
@chmod($newrandomfilenamewithpath, 0644);
}
if ($this->errorback){
$this->whichfields = substr($this->whichfields, 0, -1);
header("Location: ../?err=uploadfileproblem&whichfields=$this->whichfields");
exit;
} else {
//## everything OK
// back to file
}
} // end fucnction upload_add_ad
##########
} // end class