Is the way i am handling image uploads secure? Is there ANY way someone could upload a .php file, or some other file which can somehow execute php code (even if the attacker would know the actual file path after the upload?)
function random($longueur = 10)
{
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($longueur/strlen($x)) )),1,$longueur);
}
$random = random(5);
//POST DATA
$img_name = htmlspecialchars($_POST["img_name"]);
//IMAGE
mkdir('../../assets/images/'.$random.'/');
$target_dir = '../../assets/images/'.$random.'/';
$target_file = $target_dir . basename($_FILES["img_src"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
//ARRAY EXTENSION GOOD
$extension_autorisee = array('.png', '.jpg', '.jpeg', 'png', 'jpg', 'jpeg');
if (in_array($imageFileType, $extension_autorisee)){
//MOVE IMAGE
move_uploaded_file($_FILES["img_src"]["tmp_name"], $target_file);
$filename = $random."/".$_FILES['img_src']['name'];
}