Nextrek
@ 533
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<?php require_once("repositories/UserRepository.php"); require_once("constants.php"); $servername = "localhost"; $username = "smartcharging"; $password = "LXRLBaEAuRr7M7jY"; $conn; $risposta = array(); $user_repo; try { $conn = new PDO("mysql:host=".$servername.";dbname=smartcharging", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //echo "Connesso con successo al DB"; if (!array_key_exists("token", $_POST) || !UserRepository::checkToken($_POST["token"], $conn)) { $risposta["return"] = -1; echo json_encode($risposta); die(); } if (!array_key_exists("user_id", $_POST) || !array_key_exists("avatar_name", $_POST)) { $risposta["return"] = 1; $risposta["avatar_name"] = ""; echo json_encode($risposta); die(); } if(isset($_FILES['avatar_file'])) { $file = $_FILES['avatar_file']; if($file['error'] == UPLOAD_ERR_OK and is_uploaded_file($file['tmp_name'])) { move_uploaded_file($file['tmp_name'], $_SERVER['DOCUMENT_ROOT'].AVATAR_PATH.$_POST["avatar_name"]); } } $user_repo = new UserRepository($conn); $risposta = $user_repo->setAvatar($_POST["user_id"], $_POST["avatar_name"]); } catch(PDOException $e) { echo $e->getMessage(); $risposta["return"] = 1; $risposta["avatar_name"] = ""; } echo json_encode($risposta); $conn = null; //Close the connection to the DBMS ?> |