$target_dir = "../public/images/"; if (isset($_POST["name"]) && isset($_FILES["fileToUpload"]["name"])) { $nameFile = strtotime("now") . $_FILES["fileToUpload"]["name"]; $target_file = $target_dir . basename($nameFile); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); if ($_FILES["fileToUpload"]["size"] > 500000) { $message = "File quá lớn, vui lòng sử dụng file nhẹ hơn!"; $uploadOk = 0; } if ( $imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { $message = "File của bạn không phải file ảnh, vui lòng chọn file khác!"; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo ""; // if everything is ok, try to upload file } else move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);