2019-10-14 00:56:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Nom du fichier image
|
|
|
|
$filename = $_FILES['image']['name'] ?? $_FILES['add_image']['name'];
|
|
|
|
|
2019-10-14 14:54:18 +02:00
|
|
|
// Emplacement
|
2019-10-14 00:56:07 +02:00
|
|
|
$path = str_replace('\\', '/', dirname(realpath(__DIR__)));
|
2019-11-03 20:33:51 +01:00
|
|
|
$source = $_POST['source'];
|
|
|
|
$location = $path.'/uploads/'.$source.'/';
|
2019-10-14 02:04:47 +02:00
|
|
|
|
2019-10-14 14:54:18 +02:00
|
|
|
// Extension du fichier
|
2019-10-15 00:09:23 +02:00
|
|
|
$file_extension = pathinfo($filename, PATHINFO_EXTENSION);
|
2019-10-14 00:56:07 +02:00
|
|
|
$file_extension = strtolower($file_extension);
|
|
|
|
|
2019-10-14 14:54:18 +02:00
|
|
|
// Extensions valides d'image
|
2019-10-14 00:56:07 +02:00
|
|
|
$image_ext = array("jpg","png","jpeg");
|
2019-10-15 00:09:23 +02:00
|
|
|
$nom_user = $_POST['nom_user'];
|
|
|
|
$nom_antenne = $_POST['nom_antenne'];
|
2019-10-14 00:56:07 +02:00
|
|
|
$response = 0;
|
|
|
|
if(in_array($file_extension,$image_ext)){
|
2019-10-15 00:09:23 +02:00
|
|
|
$directory = $location.$nom_antenne;
|
|
|
|
if (file_exists($directory) === false) {
|
|
|
|
mkdir($directory, 0777, true);
|
|
|
|
}
|
|
|
|
$nom_fichier = $nom_antenne.'-'.$nom_user.'-'.uniqid("",true).'.'.$file_extension;
|
2019-11-03 20:33:51 +01:00
|
|
|
$location2 = '/uploads/'.$source.'/'.$nom_antenne.'/'.$nom_fichier;
|
2019-10-14 00:56:07 +02:00
|
|
|
// Upload du fichier
|
2019-10-15 00:09:23 +02:00
|
|
|
if(move_uploaded_file($_FILES['image']['tmp_name']
|
|
|
|
?? $_FILES['add_image']['tmp_name'],$directory.'/'.$nom_fichier)){
|
2019-10-14 00:56:07 +02:00
|
|
|
$response = $location2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $response;
|