如何使用PHP上传pdf文件中的代码 [英] Codes in how to upload pdf file using PHP

查看:114
本文介绍了如何使用PHP上传pdf文件中的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在PHP中上传PDF文件的代码.可以为我提供带有修改后的上传大小的示例代码吗?任何帮助表示赞赏.是否可以将其保存到数据库并可以将其删除?谢谢!

I don't know the codes in how to upload the PDF file in PHP. Can I have a sample codes for it with a modified upload size? Any help is appreciated. Is it possible to save it to database and can delete it? Thanks!

推荐答案

有很多教程.此 教程 为我工作

There is a lot of tutorials out there. This tutorial worked for me.

步骤1 –选择文件的基本用户界面

<form action="upload_file.php" method="post" enctype="multipart/form-data">

<input type="file" name="file" size="50" />

<br />

<input type="submit" value="Upload" />

</form>

步骤2 –将文件上传到服务器PHP脚本

<?php

 $targetfolder = "testupload/";

 $targetfolder = $targetfolder . basename( $_FILES['file']['name']) ;

if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder))

 {

 echo "The file ". basename( $_FILES['file']['name']). " is uploaded";

 }

 else {

 echo "Problem uploading file";

 }

 ?>

限制文件类型/使用PHP脚本上传图像

<?php

 $targetfolder = "testupload/";

 $targetfolder = $targetfolder . basename( $_FILES['file']['name']) ;

 $ok=1;

$file_type=$_FILES['file']['type'];

if ($file_type=="application/pdf" || $file_type=="image/gif" || $file_type=="image/jpeg") {

 if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder))

 {

 echo "The file ". basename( $_FILES['file']['name']). " is uploaded";

 }

 else {

 echo "Problem uploading file";

 }

}

else {

 echo "You may only upload PDFs, JPEGs or GIF files.<br>";

}

?>

这篇关于如何使用PHP上传pdf文件中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆