File: /home/imensosw/www/imenso.co/demo/claapp/config/function.php
<?php
function uploadfile($store_path,$file_name)
{
$target_dir = $store_path;
$temp = explode(".",$_FILES[$file_name]["name"]);
$newfilename =trim($temp[0]).round(microtime(true)) . '.' . end($temp);
$target_file = $target_dir .$newfilename;
$error=$success="";
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
// Check if file already exists
if (file_exists($target_file)) {
$error="Sorry, file already exists.";
}
// Check file size
if ($_FILES[$file_name]["size"] > 500000000) {
$error="Sorry, your file is too large.";
}
// Allow certain file formats
if($imageFileType != "pdf" ) {
$error="Sorry, only pdf files are allowed.";
}
if(!is_writable($store_path))
{
$error='You cannot upload to the specified directory, please CHMOD it to 777.';
}
// Check if $uploadOk is set to 0 by an error
if ($error =="") {
if (move_uploaded_file($_FILES[$file_name]["tmp_name"], $target_file)) {
$success=$newfilename;
} else {
$error="Sorry, there was an error uploading your file.";
}
}
if($success!="")
{
return json_encode(array('status'=>'success','msg'=>$success));
}
return json_encode(array('status'=>'error','msg'=>$error));
}
?>