/ Published in: PHP
Code to upload a file in PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php if($_FILES['photo']['name']) { //if no errors... if(!$_FILES['file']['error']) { //now is the time to modify the future file name and validate the file if($_FILES['file']['size'] > (1024000)) //can't be larger than 1 MB { $valid_file = false; $message = 'Oops! Your file\'s size is to large.'; } //if the file has passed the test if($valid_file) { //move it to where we want it to be $message = 'File uploaded successfully.'; } } //if there is an error... else { //set that to be the returned message $message = 'Something got wrong while uploading file: '.$_FILES['file']['error']; } } ?>
URL: https://www.onlineinterviewquestions.com/code-to-upload-file-in-php/