Posts

Showing posts from October, 2018

How to upload image in php ?

<?php header('Content-Type: application/json'); include '../connection.php'; $target_dir = "../upload/profile/"; $userId = $_POST['userId']; $target_file = $target_dir . basename($_FILES["profile_photo"]["name"]); $message=""; $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image $check = getimagesize($_FILES["profile_photo"]["tmp_name"]); if($check !== false) {         // echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { $message =  "File is not an image."; $uploadOk = 0; } // Check if file already exists if (file_exists($target_file)) { $message = "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["profile_photo"]["size"] > 500000) { $message = "