【发布时间】:2013-12-31 16:20:29
【问题描述】:
我正在尝试使用 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"> 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 到数据库...... 我假设在确定大小时会出现这个问题,但我不知道如何解决。
【问题讨论】:
-
也许 mimetype 不正确,所以检查一下。
-
你能对此进行至少一些的调试吗?在每种情况下,您只需
return "1",它实际上并没有告诉您任何有用的信息。当您单步执行代码时,它在哪里以及如何失败?
标签: php mysql forms pdf ms-word