gpt4 book ai didi

php - 使用PHP表单上传PDF到数据库

转载 作者:行者123 更新时间:2023-11-30 00:52:23 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 将 pdf 或 word 文件上传到 mysql 数据库。我的代码适用于我指定的图像,但不适用于 pdf 和 word 文件。

这是我的代码,其中包含表单表格和 php 代码:

<?php
include("./upload.php");

$dosyayolu="resimler/";
$logos=yukleyici("logo",2048*1024,$dosyayolu);
$links=yukleyici("link",20000000000000,$dosyayolu);

if($logos!="1"){
if($_POST['baslik']!=""){
if(mysql_query("INSERT INTO gfsidocuments (baslik,logo,detay,link)
VALUES ('".$_POST['baslik']."','".$logos."','".$_POST['detay']."','".$links."')"));
header( 'Location: ./gfsidocedit.php');
}
}
}
?>


<table border="0" width="100%" height="40" cellspacing="0" cellpadding="0">
<tr>
<td width="100" bgcolor="#E1E1E1"><font face="Tahoma" size="2">&nbsp;Document</font></td>
<td width="238" bgcolor="#E1E1E1"><input type="file" name="link" id="link" size="20"></td>
<td width="211" bgcolor="#E1E1E1"></td>
<td bgcolor="#E1E1E1"></td>
</tr>
</table>

这是 upload.php :

<?php
function yukleyici($filefield,$limit,$folder){
if ( ($_FILES[$filefield]["type"] == "image/gif")
|| ($_FILES[$filefield]["type"] == "image/jpeg")
|| ($_FILES[$filefield]["type"] == "image/png")
|| ($_FILES[$filefield]["type"] == "application/pdf")
|| ($_FILES[$filefield]["type"] == "application/msword")
)
{
if(($_FILES[$filefield]["size"] < $limit)){
$filename=getUniqueName() . $_FILES[$filefield]["name"];
if(move_uploaded_file($_FILES[$filefield]["tmp_name"],
realpath("../") . "/" . $folder . $filename)){
return $folder . $filename;
}else{
return "1";
}
}else{
return "1";
}
}else{
return "1";
}
}
function getUniqueName(){
return substr(md5(uniqid(rand(), true)),1,10);
}
?>

正如我所说,当我上传图像时,它可以工作,但是当我上传 pdf 或 word 文档时,它会向数据库返回 1...我假设确定尺寸有问题,但我不知道如何解决。

最佳答案

我不确定,但我认为问题出在以下几行:

$logos=yukleyici("logo",2048*1024,$dosyayolu); //that means pixel

if($logos!="1"){ ...

关于php - 使用PHP表单上传PDF到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20860189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com