getUniqueID("crmentity");
$desc = $_REQUEST['txtDescription'];
$description = addslashes($desc);
$date_var = date('YmdHis');
$data = base64_encode(fread(fopen($uploaddir.$binFile, "r"), $filesize));
//$data = addslashes(fread(fopen($uploaddir.$binFile, "r"), $filesize));
$query = "insert into crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime) values('";
$query .= $current_id."','".$current_user->id."','".$current_user->id."','".$_REQUEST['return_module'].' Attachment'."','".$description."','".$date_var."')";
$result = $adb->query($query);
$sql = "insert into attachments values(";
$sql .= $current_id.",'".$filename."','".$description."','".$filetype."','".$filesize."','".$adb->getEmptyBlob()."')";
$result = $adb->query($sql);
if($result!=false)
$result = $adb->updateBlob('attachments','attachmentcontents',"attachmentsid='".$current_id."' and name='".$filename."'",$data);
$crmid = $_REQUEST['return_id'];
$sql1 = "insert into seattachmentsrel values('";
$sql1 .= $crmid."','".$current_id."')";
$result = $adb->query($sql1);
header("Location: index.php?action=".$_REQUEST['return_action']."&module=".$_REQUEST['return_module']."&record=".$_REQUEST['return_id']."&filename=".$filename."");
}
else
{
include('themes/'.$theme.'/header.php');
$errormessage = "Error Message
- Invalid file OR
- File has no data
" ;
echo $errormessage;
deleteFile($uploaddir,$filename);
include "upload.php";
}
}
else
{
$errorCode = $_FILES['binFile']['error'];
if($errorCode == 4)
{
include('themes/'.$theme.'/header.php');
$errormessage = "Kindly give a valid file for upload!
" ;
echo $errormessage;
include "upload.php";
}
else if($errorCode == 2)
{
$errormessage = "Sorry, the uploaded file exceeds the maximum filesize limit. Please try a file smaller than 1000000 bytes
";
include('themes/'.$theme.'/header.php');
echo $errormessage;
include "upload.php";
//echo $errorCode;
}
else if($errorCode == 3 || $errorcode == '')
{
include('themes/'.$theme.'/header.php');
echo "Problems in file upload. Please try again!
";
include "upload.php";
}
}
function deleteFile($dir,$filename)
{
unlink($dir.$filename);
}
?>