Home  >  Article  >  Backend Development  >  Simple example of uploading pdf files in php

Simple example of uploading pdf files in php

WBOY
WBOYOriginal
2016-07-25 08:56:532529browse
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>

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
?>


Statement:
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