<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
check if file is type of image
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "file is an image " . $check['mime'] .".";
$uploadOk = 1;
} else {
echo "file is not an image";
$uploadOk = 0;
}
}
if ($uploadOk == 0) {
echo "problem occured while uploading";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "image file ". basename( $_FILES["fileToUpload"]["name"]). " has been successfully uploaded.";
} else {
echo " problem occured while uploading";
}
}
No hay comentarios:
Publicar un comentario