<?
class functions
{
private $table;
private $db;
public function __construct($table = "patient")
{
$this->table = $table;
$this->db = new Database();
}
// Ici la suite du code
function sanitize_my_email($field) {
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
if (filter_var($field, FILTER_VALIDATE_EMAIL)) {
return true;
} else {
return false;
}
}
// Envoyer un email
public function sendmail($to_email,$subject,$message,$headers)
{
$to =$to_email;
$sujet =$subject;
$msg =$message;
$head =$headers;
//check if the email address is invalid $secure_check
$secure_check = sanitize_my_email($to_email);
if ($secure_check == false) {
echo "Invalid input";
} else { //send email
mail($to, $sujet, $msg, $head);
echo "This email is sent using PHP Mail";
}
}
//upload file and extension tolerable
public function uploadfile($nameOfinput){
$currentDir = getcwd();
$uploadDirectory = "/uploads/";
$errors = []; // Store all foreseen and unforseen errors here
$fileExtensions = ['jpeg','jpg','png']; // Possible extensions
$fileName = $_FILES[$nameOfinput]['name'];
$fileSize = $_FILES[$nameOfinput]['size'];
$fileTmpName = $_FILES[$nameOfinput]['tmp_name'];
$fileType = $_FILES[$nameOfinput]['type'];
$fileExtension = strtolower(end(explode('.',$fileName)));
$uploadPath = $currentDir . $uploadDirectory . basename($fileName);
if (isset($_POST['submit'])) {
if (! in_array($fileExtension,$fileExtensions)) {
$errors[] = "This file extension is not allowed. Please upload a JPEG or PNG file";
}
if ($fileSize > 2000000) {
$errors[] = "This file is more than 2MB. Sorry, it has to be less than or equal to 2MB";
}
if (empty($errors)) {
$didUpload = move_uploaded_file($fileTmpName, $uploadPath);
if ($didUpload) {
echo "The file " . basename($fileName) . " has been uploaded";
} else {
echo "An error occurred somewhere. Try again or contact the admin";
}
} else {
foreach ($errors as $error) {
echo $error . "These are the errors" . "\n";
}
}
}
}
}
?>
class functions
{
private $table;
private $db;
public function __construct($table = "patient")
{
$this->table = $table;
$this->db = new Database();
}
// Ici la suite du code
function sanitize_my_email($field) {
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
if (filter_var($field, FILTER_VALIDATE_EMAIL)) {
return true;
} else {
return false;
}
}
// Envoyer un email
public function sendmail($to_email,$subject,$message,$headers)
{
$to =$to_email;
$sujet =$subject;
$msg =$message;
$head =$headers;
//check if the email address is invalid $secure_check
$secure_check = sanitize_my_email($to_email);
if ($secure_check == false) {
echo "Invalid input";
} else { //send email
mail($to, $sujet, $msg, $head);
echo "This email is sent using PHP Mail";
}
}
//upload file and extension tolerable
public function uploadfile($nameOfinput){
$currentDir = getcwd();
$uploadDirectory = "/uploads/";
$errors = []; // Store all foreseen and unforseen errors here
$fileExtensions = ['jpeg','jpg','png']; // Possible extensions
$fileName = $_FILES[$nameOfinput]['name'];
$fileSize = $_FILES[$nameOfinput]['size'];
$fileTmpName = $_FILES[$nameOfinput]['tmp_name'];
$fileType = $_FILES[$nameOfinput]['type'];
$fileExtension = strtolower(end(explode('.',$fileName)));
$uploadPath = $currentDir . $uploadDirectory . basename($fileName);
if (isset($_POST['submit'])) {
if (! in_array($fileExtension,$fileExtensions)) {
$errors[] = "This file extension is not allowed. Please upload a JPEG or PNG file";
}
if ($fileSize > 2000000) {
$errors[] = "This file is more than 2MB. Sorry, it has to be less than or equal to 2MB";
}
if (empty($errors)) {
$didUpload = move_uploaded_file($fileTmpName, $uploadPath);
if ($didUpload) {
echo "The file " . basename($fileName) . " has been uploaded";
} else {
echo "An error occurred somewhere. Try again or contact the admin";
}
} else {
foreach ($errors as $error) {
echo $error . "These are the errors" . "\n";
}
}
}
}
}
?>
Commentaires
Enregistrer un commentaire