$nbjmax){ If (unlink($ficlog)) { // file was successfully deleted } else { // there was a problem deleting the file } } } //$msg.=' -today:' . $aujourdhui . ' -modif:' . $datemodif; date_default_timezone_set('Europe/Paris'); $dateselect =date('Y-m-d H:i:s'); $ficl=fopen($ficlog, "a");fwrite($ficl,date('Y-m-d H:i:s').' '.$pid . ' ' .$pgm.$fonc.':'.$msg."\r\n");fclose($ficl); return $ok; } $VERSION="1.1.04"; $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // log 1P $msg="";$pgm=basename(__FILE__, '.php');$fonc='.Main ';$ok='ko'; $dbg=1; $pid='123'; $msg= $VERSION . ' root: ' . $_SERVER["DOCUMENT_ROOT"] .' url de connexion: ' . $actual_link;$ok=logmsg($pid, "access.txt",$msg, $pgm, $fonc); // root: C:/$user/httdocs url de connexion: http://localhost/php/webservices/WS_REST/upload/upload-api-file.php // root: /home/obhc6145/public_html/schwobbruno.com url de connexion: https://www.schwobbruno.com/upload-api-file.php // ===================================================== $msg="";$pgm='upload';$fonc='.Main ';$ok='ko'; // recup headers pour log.txt------------------------------------------------------------------------ $allsvr=''; $headers = array(); foreach($_SERVER as $key => $value){ if(preg_match("/^HTTP_/", $key)) $headers[$key] = $value; $strval=print_r($value, true);//conversion de Array en string $allsvr.= ' k:' . $key . ' val:' . $strval; } $prtheaders=''; foreach ($headers as $key => $value) { $prtheaders=$prtheaders. "$key => $value" . " "; } $msg=' -headers: ' . $prtheaders;$ok=logmsg($pid,"log.txt",$msg, $pgm, $fonc); $msg=' -headers: ' . $allsvr ;$ok=logmsg($pid,"log.txt",$msg, $pgm, $fonc); $data = json_decode(file_get_contents("php://input"), true); // collect input parameters and convert into readable format $msg = ' -body:' . $data;$ok=logmsg($pid,"log.txt",$msg, $pgm, $fonc); $fileName = $_FILES['sendimage']['name']; $tempPath = $_FILES['sendimage']['tmp_name']; $fileSize = $_FILES['sendimage']['size']; // TRT ===================================================== if(empty($fileName)){ $errorMSG = json_encode(array("message" => "please select image", "status" => false)); echo $errorMSG; } else{ $upload_path = __dir__ . '/uploaded/'; // dir du upload $fileExt = strtolower(pathinfo($fileName,PATHINFO_EXTENSION)); // get image extension $file = strtolower(pathinfo($fileName,PATHINFO_FILENAME)); // get image extension $msg="";$pgm='upload';$fonc='.Main ';$ok='ko'; $msg='upload_path:' . $upload_path . ' file:' . $file . ' fileExt:' . $fileExt . ' dir:' . __dir__; $ok=logmsg($pid,'log.txt',$msg, $pgm, $fonc); $msg=""; $msg='fileName:'.$fileName.' tempPath:'.$tempPath.' fileSize:'.$fileSize; $ok=logmsg($pid,'log.txt',$msg, $pgm, $fonc); // valid image extensions $valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'txt'); // allow valid image file formats if(in_array($fileExt, $valid_extensions)){ //check file not exist our upload folder path if(!file_exists($upload_path . $fileName)){ // check file size '5MB' if($fileSize < 5000000){ move_uploaded_file($tempPath, $upload_path . $fileName); // move file from system temporary path to our upload folder path } else{ $errorMSG = json_encode(array("message" => "Sorry, your file is too large, please upload 5 MB size", "status" => false)); echo $errorMSG; } } else{ $errorMSG = json_encode(array("message" => "Sorry, file already exists check upload folder", "status" => false)); echo $errorMSG; } } else{ $errorMSG = json_encode(array("message" => "Sorry, only JPG, JPEG, PNG & GIF files are allowed", "status" => false)); echo $errorMSG; } } // // if no error caused, continue .... ===================================================== // on enregistre le path dans DB if(!isset($errorMSG)){ $conn = open_connexion(); $str = str_replace("\\", '/', __dir__); $query = mysqli_query($conn,'INSERT into pages (user,page,content) VALUES("'.$fileExt.'","' . $file . '","' . $str . '")'); echo json_encode(array("message" => "Image Uploaded Successfully", "status" => true)); } ?>