How to Create a File Type Validation using PHP

How to Create a File Type Validation using PHP

In this Post We Will Explain About is How to Create a File Type Validation using PHP With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to php check file extension in upload form Example

In this post we will show you Best way to implement How to securely upload files with PHP, hear for How To Handle File Uploads With PHP with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  how to decode json in php

Creating simple Form

first of all, we make simple HTML form which data contains simple file upload HTML input field.

Make a new simple file, name it Like as index.php and copy data & paste the source codes below.

<?php session_start(); ?>
<!DOCTYPE html>
	<meta charset="utf-8">
	<title>How to Make a File Type Validation using PHP</title>
	<link rel="stylesheet" type="text/css" href="pakainfo/bootstrap4/css/bootstrap.min.css">
<div class="pakainfo container">
	<h1 class="pakainfo text-center" style="margin-top:30px;">File Type Validation using PHP</h1>
	<div class="pakainfo row justify-content-center">
		<div class="col-sm-4">
					echo "
						<div class='alert alert-danger text-center'>
					echo "
						<div class='pakainfo alert alert-success text-center'>
			<div class="pakainfo card">
				<div class="card-body">
					<form method="POST" action="authorize.php" enctype="multipart/form-data">
					    <input type="file" class="form-control-file" name="file" required><br>
					    <button type="submit" class="btn btn-primary" name="authorize">Validate</button>

Making simple Validation

And then, we make simple HTML validation if simple HTML form is submitted to check data and input for the Like as a file/mime type of the PHP serever side uploaded file.

Read Also:  Laravel 6 select distinct and order by Example

MAke a new file, name it as Serever side Like as authorize.php and copy and paste the source codes below.

 //pakainfo example
		//free type
		$permit = array('jpg', 'png', 'jpeg');
		$file = $_FILES['file']['name'];
		$ext = pathinfo($file, PATHINFO_EXTENSION);

		if(in_array($ext, $permit)){

			$_SESSION['success'] = 'Your File type permit';

			$_SESSION['custom_err'] = 'Your File type not permit';
		$_SESSION['custom_err'] = 'Please Upload a file to authorize first';
	header('location: index.php');

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Read Also:  Laravel Group by not working - LIMIT or GROUP BY with prepared statement not working


I hope you have Got What is How to create PHP based email form with file attachment And how it works.I would Like to have FeedBack From My Blog( readers.Your Valuable FeedBack,Any Question,or any Comments about This Article( Are Most Always Welcome.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Send Beautiful HTML Email Templates
  2. Read Also:  integration Google No CAPTCHA reCAPTCHA using Laravel
  3. Read Also:  Laravel 6 drop column if exists MySQL using Migration
  4. Read Also:  Class 'PhpParser\Parser\Php7' not found
  5. Read Also:  how to disable previous date in bootstrap datepicker?
  6. Read Also:  PHP Simple Image Upload and Display Source Code
  7. Read Also:  Woocommerce get price in custom loop
  8. Read Also:  PHP Parse URL Querystring Into Array
  9. Read Also:  Laravel 6 drop column if exists MySQL using Migration
  10. Read Also:  PHP Parse URL Querystring Into Array