用php上传pdf文件到mysql数据库

时间:2017-10-09 20:52:45

标签: php mysql

我没有错误,连接正常,但我的数据库没有收到任何数据。我一直在关注一个教程而不是我自己的代码,但是我无法看到我在哪里犯了错误。

我创建了一个名为files的表,它与下面代码中使用的参数相对应。

代码位于名为uploader.php的文件中:

<?php if(isset($_POST['uploader']) && $_FILES['userfile']['size'] > 0)

 {
 echo "working";
 $fileName = $_FILES['userfile']['name'];

$tmpName  = $_FILES['userfile']['tmp_name'];

$fileSize = $_FILES['userfile']['size'];

$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');

$content = fread($fp, filesize($tmpName));

$content = addslashes($content);

fclose($fp);

if(!get_magic_quotes_gpc())

{

$fileName = addslashes($fileName);

}

mysql_connect("localhost","root","root");

mysql_select_db("globe_bank");

$query = "INSERT INTO files (name, size, type, content ) ".

"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');

echo "
File $fileName uploaded
";

}

?>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellspacing="1" cellpadding="1">
<tbody>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />

<input id="userfile" type="file" name="userfile" /></td>
<td width="80"><input id="uploader" type="submit" name="uploader" value=" Uploader " /></td>
</tr>
</tbody>
</table>
</form> 

0 个答案:

没有答案