Created
February 27, 2019 13:40
-
-
Save ErMandeep/929e783ba9ab12598a5ffcb841d85999 to your computer and use it in GitHub Desktop.
upload file into folder simple method and show error if any
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_POST['submit'])){ | |
echo "<pre>"; | |
print_r($_FILES['file_upload']); | |
echo "</pre>"; | |
$upload_error = array( | |
UPLOAD_ERR_OK => "There is no error", | |
UPLOAD_ERR_INI_SIZE =>"The uploaded file exceed the upload file size limit", | |
UPLOAD_ERR_FORM_SIZE =>"The uploaded file exceed the MAX_FILE_SIZE directively", | |
UPLOAD_ERR_PARTIAL =>"The uploaded file was only partialy uploaded. ", | |
UPLOAD_ERR_NO_FILE =>"No file was upload", | |
UPLOAD_ERR_NO_TMP_DIR =>"Missing a tempary folder.", | |
UPLOAD_ERR_CANT_WRITE =>"Failed to write file to disk", | |
UPLOAD_ERR_EXTENSION =>"A php extension stopped the file upload" | |
); | |
$temp_name = $_FILES['file_upload']['tmp_name']; | |
$the_file = $_FILES['file_upload']['name']; | |
$directory = "uploads"; | |
if(move_uploaded_file($temp_name, $directory."/".$the_file)){ | |
$the_message = "File upload Successfully."; | |
}else{ | |
$the_error = $_FILES['file_upload']['error']; | |
$the_message = $upload_error[$the_error]; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<form action="upload.php" enctype="multipart/form-data" method="post"> | |
<h2> | |
<?php | |
if(!empty($upload_error)){ | |
echo $the_message; | |
} | |
?> | |
</h2> | |
<input type="file" name="file_upload"><br> | |
<input type="submit" name="submit"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment