Image Upload Without Validation With Proper Explanation Using PHP Along With Coding

Image Upload Without Validation With Proper Explanation Using PHP Along With Coding

NOTE: To upload the Image I have created one new folder "uploads" which I have used within my code "$folder="uploads/".$fileName" within my folder "Image Upload Without Validation".

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:

Image Upload Without Validation.php

<!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

Popular posts from this blog

Programmings Based On Array And String Functions To Merge The 2 Arrays, Then After Merge Convert Into String And Then Find Out The 1st And Last Word From The Reverse String

PHP WEB DEVELOPMENT INTERVIEW QUESTIONS ASKED IN APOLLO HOSPITAL ALONG WITH MY OWN CONCEPTS AND MY OWN EXPLANATION ANSWERS(PART - 1) REST OF THE QUESTIONS AND ANSWERS WILL BE PREPARED BY ME IN MY NEXT BLOG

Mini Project On Multi User CRUD Operations(Create, Read, Update & Delete) Of Donar Details Of Indian Nationals Who Donate To Ramkrishna Math, Belur Math Using PDO (PHP Data Objects) With Proper Explanation Of Each And Every Individual Line Of The Code Of connection.php Page, form.php Page, formaction.php Page, admin_display.php Page, client_display.php Page, edit.php Page, editaction.php Page And delet.php Page (Here You Will Find The Image Of Sayang Sri Ramkrishna Dev, Sayang Sri Ma Sarada Devi & Sayang Sri Swami Vivekananda) In My CRUD Operation