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
2 // Store the file name into variable
3 $file = 'filename';
4 $filepath = "https://www.example.com/".$file;
5 // Header content type
6 header("Content-type: application/pdf");
7 // Send the file to the browser.
8 readfile($filepath);
9