Image Upload Without Validation With Proper Explanation Using PHP Along With Coding
Image Upload Without Validation With Proper Explanation Using PHP Along With Coding
So, just let me explain here why I have used enctype="multipart/form-data" in Image Upload Without Validation.php page. Hooray, let's begin.
Here I have used enctype="multipart/form-data" as because text can be converted into binary by default. But image or file cannot be converted into binary by default. So, to convert the image or file into binary, I have used encrypt type (enctype) here. So, what does machine understands? I know that machine understand only 0 and 1 in his language. Machine doesn't understand any other language. So, in backend when the data is passing from User Interface (UI), it will count as binary only. That's why, here I have used enctype="multipart/form-data".
Codes:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Image Upload Without Validation</title>
</head>
<body>
<form method="post" action="fileaction.php" enctype="multipart/form-data">
Image Upload: <input type="file" name="image"><br>
<button name="btn" type="submit">Submit</button>
</form>
</body>
</html>
Now let me explain here in fileaction.php why I have used move_uploaded_file() function. Horray, let's go.
Here in fileaction.php, I have used move_uploaded_file() function as because move_uploaded_file() function is used to move the uploaded file into new destination. Like here as I have used move_uploaded_file($tmpName,$folder) means this move_uploaded_file() function move the uploaded file from $tmpName to $folder.
fileaction.php
<?php
$fileName=$_FILES['image']['name'];
$tmpName=$_FILES['image']['tmp_name'];
$folder="uploads/".$fileName;
move_uploaded_file($tmpName, $folder);
?>
<img src="<?php echo $folder; ?>" height="400px" width="400px">
Comments
Post a Comment