26 lines
717 B
PHP
26 lines
717 B
PHP
<?php
|
|
|
|
// Nom du fichier image
|
|
$filename = $_FILES['image']['name'] ?? $_FILES['add_image']['name'];
|
|
|
|
// Emplacement
|
|
$path = str_replace('\\', '/', dirname(realpath(__DIR__)));
|
|
$location = $path.'/uploads/products/'.$filename;
|
|
$location2 = '/uploads/products/'.$filename;
|
|
|
|
// Extension du fichier
|
|
$file_extension = pathinfo($location, PATHINFO_EXTENSION);
|
|
$file_extension = strtolower($file_extension);
|
|
|
|
// Extensions valides d'image
|
|
$image_ext = array("jpg","png","jpeg");
|
|
|
|
$response = 0;
|
|
if(in_array($file_extension,$image_ext)){
|
|
// Upload du fichier
|
|
if(move_uploaded_file($_FILES['image']['tmp_name'] ?? $_FILES['add_image']['tmp_name'],$location)){
|
|
$response = $location2;
|
|
}
|
|
}
|
|
|
|
echo $response; |