1<html>
2<head>
3<title> FORM </title>
4</head>
5<body align="left">
6<h1> FILE UPLOAD </h1>
7
8<form action = "term5b.php" method = "POST" enctype="multipart/form-data"/>
9
10 <input type = "file" name = "fileupload"/></br>
11 <input type = "submit" name = "opt" value = "upload"/></br> </br>
12
13</form>
14</body>
15</html>
16
17
18
19
20
21
22
23<?php
24 $target_dir="E:\ ";
25 $filename=$_FILES["fileupload"]["name"];
26
27 $tmpname=$_FILES["fileupload"]["tmp_name"];
28 $filetype=$_FILES["fileupload"]["type"];
29 $errors=[];
30 $fileextensions=["pdf"];
31 $arr=explode(".",$filename);
32 $ext=strtolower(end($arr));
33
34 $uploadpath=$target_dir.basename($filename);
35if(! in_array($ext,$fileextensions))
36 {
37 $errors[]="Invalid filename";
38 }
39 if(empty($errors))
40 {
41 if(move_uploaded_file($tmpname,$uploadpath))
42 {
43 echo "file uploaded successfully";
44 }
45 else
46 {
47 echo "not successfull";
48 }
49 }
50 else
51 {
52 foreach($errors as $value)
53 {
54 echo "$value";
55 }
56 }
57?>
58
1<?php include 'filesLogic.php';?>
2<!DOCTYPE html>
3<html lang="en">
4 <head>
5 <link rel="stylesheet" href="style.css">
6 <title>Files Upload and Download</title>
7 </head>
8 <body>
9 <div class="container">
10 <div class="row">
11 <form action="index.php" method="post" enctype="multipart/form-data" >
12 <h3>Upload File</h3>
13 <input type="file" name="myfile"> <br>
14 <button type="submit" name="save">upload</button>
15 </form>
16 </div>
17 </div>
18 </body>
19</html>