31 lines
892 B
PHP
31 lines
892 B
PHP
<?php
|
|
|
|
// Nom du fichier image
|
|
$filename = $_FILES['avatar']['name'];
|
|
|
|
// Emplacement
|
|
$path = str_replace('\\', '/', dirname(realpath(__DIR__)));
|
|
$location = $path.'/uploads/avatars/';
|
|
|
|
// Extension du fichier
|
|
$file_extension = pathinfo($filename, PATHINFO_EXTENSION);
|
|
$file_extension = strtolower($file_extension);
|
|
|
|
// Extensions valides d'image
|
|
$image_ext = array("jpg","png","jpeg");
|
|
$nom_user = $_POST['nom_user'];
|
|
$response = 0;
|
|
if(in_array($file_extension,$image_ext)){
|
|
$directory = '/uploads/avatars';
|
|
if (file_exists($directory) === false) {
|
|
mkdir($directory, 0777, true);
|
|
}
|
|
$nom_fichier = $nom_user.'-'.uniqid("",true).'.'.$file_extension;
|
|
$location2 = '/uploads/avatars/'.$nom_fichier;
|
|
// Upload du fichier
|
|
if(move_uploaded_file($_FILES['avatar']['tmp_name'],$directory.'/'.$nom_fichier)){
|
|
$response = $location2;
|
|
}
|
|
}
|
|
|
|
echo $response; |