Simple example of uploading pdf files in php

WBOY
Release: 2016-07-25 08:56:53
Original
2535 people have browsed it
This article introduces a piece of php code for uploading pdf files to the website space. Friends in need can refer to it.

Use php to upload files in pdf format.

1, html part

<form action="<?php print $PHP_SELF?>" enctype="multipart/form-data" method="post">
Last name:<br /> <input type="text" name="name" value="" /><br />
class notes:<br /> <input type="file" name="classnotes" value="" /><br />
  <input type="submit" name="submit" value="Submit Notes" />
</form>
Copy after login

2. The code for uploading pdf files requires file format detection, here it is: application/pdf.

<?php
 define ("filesplace","./");

 if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {

 if ($_FILES['classnotes']['type'] != "application/pdf") {
 echo "<p>请上传 PDF 格式的文件.</p>";
 } else {
 $name = $_POST['name'];
 $result = move_uploaded_file($_FILES['classnotes']['tmp_name'], filesplace."/$name.pdf");
 if ($result == 1) echo "<p>成功上传。</p>";
 else echo "<p>对不起,上传发生错误。 </p>";
} #endIF
 } #endIF
?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template