Simple File Upload Code in PHP


Below  Code is Used to Upload Files in PHP Code


File 1 :  FileUpload.html

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

File 1 is used to Display the upload and submit buttons and using which we will upload the file.

File 2 :   uploader.php

<?php
$target_path = "e:/uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>

File 2 is the backend code used to upload the file.

Comments