|
本文介绍一段php代码,用于上传pdf文件到网站空间中,有需要的朋友参考下。
使用php上传pdf格式的文件。 1,html部分 <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,上传pdf文件的代码,需要做文件格式的检测,这里是: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>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/2146">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680265669916.png" alt="简篇AI排版">
</a>
<div class="aritcle_card_info">
<a href="/ai/2146">简篇AI排版</a>
<p>AI排版工具,上传图文素材,秒出专业效果!</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="简篇AI排版">
<span>554</span>
</div>
</div>
<a href="/ai/2146" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="简篇AI排版">
</a>
</div>
<p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>";
else echo "<p>对不起,上传发生错误。 </p>";
} #endIF
} #endIF
?>登录后复制 |
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号