function file_upload($file, $FolderPath = 'uploads/temp/'){

$allowedExts = array('doc','docx','rtf','ods','pdf');
$temp = explode(".", $file["name"]);
$extension = end($temp);

if (in_array($extension, $allowedExts))
{
if ($file["error"] > 0)
{
echo "Return Code: " . $file["error"] . "
";
}
else
{

$filename = str_replace(' ', '_', time().$file["name"]);

move_uploaded_file($file["tmp_name"], $FolderPath . $filename);
return $FolderPath . $filename;

}
}
else
{
$error_in_upload = "Invalid File";
return $error_in_upload;
}

}

//call function
file_upload($_FILES['file']);

Advertisements