I am trying to upload pdf or word files with PHP to mysql database. my code works with images that i specified but it doesn't work with pdf and word files.
here is my code with table of form and php code:
<?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>
Here is the 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);
}
?>
As i said when i upload image it works, but when i upload pdf or word document it returns 1 to database... İ assume that problem on determining size but i couldn't figure it out how to fix.