Home > Article > Backend Development > Simple example of uploading pdf files in php
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 ?> |