Я работаю над проектом php
, имеющим функцию загрузки и скачивания pdf-файлов.
Я загружаю его после загрузки в моем браузере и сообщает, что не удалось загрузить документ PDF
см. Мой код.
<?php
require 'connection.php';
if(isset($_POST['submit']))
{
//$insertquery = "insert into upload(department,year,semester,subject,doc,select_d) values('$department','$year','$semester','$subject','$doc','$select_d')";
$uploadOk=1;
$fileName=$_FILES['fileToUpload']['name'];
$fileName=str_replace(' ', '', $fileName);
$errorMessage="";
$fileSize="";
$fileExt="";
if($_FILES['fileToUpload']['name'])
{
$targetDir = "ss1/";
$fileName = $targetDir . uniqid().basename($fileName);
$fileSize = $_FILES['fileToUpload']['size'];
$fileType = pathinfo($fileName, PATHINFO_EXTENSION);
$fileExt = strtolower($fileType);
if($_FILES['fileToUpload']['size'] > 10000000)
{
$errorMessage = "Sorry, your file is too large";
$uploadOk = 0;
}
if(strtolower($fileType) != "pdf" && strtolower($fileType) != "doc")
{
$errorMessage = "Sorry, only pdf and docs files are allowed";
$uploadOk = 0;
}
if($uploadOk)
{
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $fileName))
{
if (file_exists($fileName)) {
echo "Sorry, file already exists.";
}
}
else
{
$uploadOk = 0;
}
}
}
if($uploadOk)
{
$department = $_POST['department'];
$year = $_POST['year'];
$semester = $_POST['semester'];
$subject = $_POST['subject'];
$doc = $_POST['doc'];
$select_d = $_POST['fileToUpload'];
$fileName = $fileName;
header("Content-type: application/pdf");
header("Content-Length: " . fileSize($fileName));
header('Content-Disposition: attachment; filename="' .$fileName.'"');
readfile($fileName);
// $check=mysqli_query($con,"SELECT * FROM upload WHERE department='$department' AND year='$year'");
if(mysqli_num_rows($check) == 0)
{
$query=mysqli_query($con,"INSERT INTO upload VALUES('','$department','$year','$semester','$subject','$doc','$fileName')");
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>SAKEC - Faculty Diary</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Glance Design Dashboard Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template,
SmartPhone Compatible web template, free WebDesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
<link rel="icon" type="image/png" href="favicon.png">
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
<!-- Custom CSS -->
<link href="css/style.css" rel='stylesheet' type='text/css' />
<!-- font-awesome icons CSS -->
<link href="css/font-awesome.css" rel="stylesheet">
<!-- //font-awesome icons CSS-->
<!-- side nav css file -->
<link href='css/SidebarNav.min.css' media='all' rel='stylesheet' type='text/css'/>
<!-- //side nav css file -->
<!-- js-->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/modernizr.custom.js"></script>
<!--webfonts-->
<link href="//fonts.googleapis.com/css?family=PT+Sans:400,400i,700,700i&subset=cyrillic,cyrillic-ext,latin-ext" rel="stylesheet">
<!--//webfonts-->
<!-- Metis Menu -->
<script src="js/metisMenu.min.js"></script>
<script src="js/custom.js"></script>
<link href="css/custom.css" rel="stylesheet">
<!--//Metis Menu -->
<style>
#chartdiv {
width: 100%;
height: 295px;
}
</style>
<!-- requried-jsfiles-for owl -->
<link href="css/owl.carousel.css" rel="stylesheet">
<script src="js/owl.carousel.js"></script>
<script>
$(document).ready(function() {
$("#owl-demo").owlCarousel({
items : 3,
lazyLoad : true,
autoPlay : true,
pagination : true,
nav:true,
});
});
</script>
<!-- //requried-jsfiles-for owl -->
</head>
<body class="cbp-spmenu-push">
<div class="main-content">
<div class="cbp-spmenu cbp-spmenu-vertical cbp-spmenu-left" id="cbp-spmenu-s1">
<!--left-fixed -navigation-->
<aside class="sidebar-left">
<nav class="navbar navbar-inverse">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h1><a class="navbar-brand" href="index.html">SAKEC<span class="dashboard_text">Faculty diary</span></a></h1>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="sidebar-menu">
<li class="treeview">
<a href="home.html">
<i class="fa fa-home"></i> <span>Home</span>
</a>
</li>
<li class="treeview">
<a href="timetable.html">
<i class="fa fa-table"></i>
<span>Time Table</span>
</a>
</li>
<li class="treeview">
<a href="calendar.html">
<i class="fa fa-calendar"></i>
<span>Calendar</span>
</a>
</li>
<li class="treeview">
<a href="syllabus.html">
<i class="fa fa-book"></i>
<span>Syllabus</span>
</a>
</li>
<li class="treeview">
<a href="planning.html">
<i class="fa fa-tasks"></i>
<span>Planning</span>
</a>
</li>
<li class="treeview">
<a href="LP_TS.html">
<i class="fa fa-tasks"></i>
<span>Lecture planning-Time scheduling</span>
</a>
</li>
<li class="treeview">
<a href="monitoring.html">
<i class="fa fa-desktop"></i>
<span>Monitoring</span>
</a>
</li>
<li class="treeview">
<a href="exam.html">
<i class="fa fa-graduation-cap"></i>
<span>Exam</span>
</a>
</li>
<li class="treeview">
<a href="activity.html">
<i class="fa fa-tasks"></i>
<span>Activities</span>
</a>
</li>
<li class="treeview">
<a href="leave.html">
<i class="fa fa-sign-out"></i>
<span>Leave details</span>
</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
</aside>
</div>
<!--left-fixed -navigation-->
<!-- header-starts -->
<div class="sticky-header header-section ">
<div class="header-left">
<!--toggle button start-->
<button id="showLeftPush"><i class="fa fa-bars"></i></button>
<!--toggle button end-->
<div><!--notification menu starts-->
</div>
<!--notification menu end -->
<div class="clearfix"> </div>
</div>
<div class="header-right">
<!--search-box-->
<div class="search-box">
</div><!--//end-search-box-->
<div class="profile_details"> <!--//profile details start-->
</div><!--//profile details end-->
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</div>
<!-- //header-ends -->
<!-- main content start-->
<div id="page-wrapper">
<div class="main-page">
<div class="file">
<h2 style="margin-left: 40%;">UPLOAD</h2><br><br>
<div id="Home" class="tabcontent">
<form method="POST" enctype="multipart/form-data">
<label style="margin-left: 4.5%">Department : </label>
<select name="department" >
<option value="IT">Information Technology</option>
<option value="CS">Computer Engineering</option>
<option value="Electical">Electronics Engineering</option>
<option value="Extc">Electronics & Telecommunication</option>
<option value="ES">Engineering Sciences</option>
</select>
<label style="margin-left: 26.5%">Year:</label>
<select name="year" >
<option value="FIRST">First Year</option>
<option value="SECOND">Second Year</option>
<option value="THIRD">Third Year</option>
<option value="FINAL">Final Year</option>
</select><br><br><br>
<label style="margin-left: 4.5%">Semester : </label>
<select name="semester" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
<label style="margin-left: 41%;">Subject :</label>
<select name="subject" >
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
<option value="4">d</option>
</select>
<br><br><br>
<label style="margin-left: 4.5%">Document Type : </label>
<select name="doc" >
<option value="Syllabus">Syllabus</option>
<option value="Assignment 1">Assignment 1</option>
<option value="Assignment 2">Assignment 2</option>
<option value="Assignment 3">Assignment 3</option>
<option value="Assignment 4">Assignment 4</option>
<option value="Tutorial 1">Tutorial 1</option>
<option value="Tutorial 2">Tutorial 2</option>
<option value="Tutorial 3">Tutorial 3</option>
<option value="Tutorial 4">Tutorial 4</option>
<option value="Tutorial 5">Tutorial 5</option>
<option value="Tutorial 6">Tutorial 6</option>
<option value="Tutorial 7">Tutorial 7</option>
<option value="Tutorial 8">Tutorial 8</option>
<option value="Tutorial 9">Tutorial 9</option>
<option value="Tutorial 10">Tutorial 10</option>
<option value="Tutorial 11">Tutorial 11</option>
<option value="Tutorial 12">Tutorial 12</option>
<option value="Internal Assessment 1">IA 1</option>
<option value="Internal Assessment 2">IA 2</option>
<option value="Internal Assessment 1 solution">IA 1 Solution</option>
<option value="Internal Assessment 2 solution">IA 2 Solution</option>
<option value="Write Ups">Write ups</option>
</select>
<label style="margin-left: 30%">Select file:</label><input type="file" style="margin-left: 54%" id="fileToUpload" name="fileToUpload">
<br><br>
</tbody>
</table>
<input type="submit" class="done" name="submit" style="background-color: rgb(96, 160, 182); margin-left: 43% ;" value="Apply"></form>
</div>
<!-- Classie --><!-- for toggle left push menu script -->
<script src="js/classie.js"></script>
<script>
var menuLeft = document.getElementById( 'cbp-spmenu-s1' ),
showLeftPush = document.getElementById( 'showLeftPush' ),
body = document.body;
showLeftPush.onclick = function() {
classie.toggle( this, 'active' );
classie.toggle( body, 'cbp-spmenu-push-toright' );
classie.toggle( menuLeft, 'cbp-spmenu-open' );
disableOther( 'showLeftPush' );
};
function disableOther( button ) {
if( button !== 'showLeftPush' ) {
classie.toggle( showLeftPush, 'disabled' );
}
}
</script>
<!-- //Classie --><!-- //for toggle left push menu script -->
<!--scrolling js-->
<script src="js/jquery.nicescroll.js"></script>
<script src="js/scripts.js"></script>
<!--//scrolling js-->
<!-- side nav js -->
<script src='js/SidebarNav.min.js' type='text/javascript'></script>
<script>
$('.sidebar-menu').SidebarNav()
</script>
<!-- //side nav js -->
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.js"> </script>
<!-- //Bootstrap Core JavaScript -->
</body>
</html>
Пожалуйста, помогите мне исправить эту ошибку.