Below we first creating a html form, which contain a field for uploading a file and a submit button for submiting form.
<html>
<body>
<form action="file_upload.php" method="post" enctype="multipart/form-data">
Select image which you want to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
secondly we are creating the Upload File in PHP . This file contain code for uploading a file.
<?php
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo " Not an image type.";
$uploadOk = 0;
}
}
?>
- $target_dir = "upload/" - It specifies the place where file get stored after uploaded.
- $target_file specifies the path of the file to be uploaded
- $imageFileType =this contains extension of the file
- Next = this check whether the image file is fake image or not.
0 Comment(s)