数据库服务器pdf⽂件,如何阅读保存在mysql数据库中的pdf⽂
件?
我已成功上传PDF⽂件到数据库,但现在当我正在尝试阅读我收到的⽂件问题“⽆法加载PDF”时,我点击链接。我检查过我的浏览器插件,没有问题。如何阅读保存在mysql数据库中的pdf⽂件?
$con=mysqli_connect("localhost","root","");
// Check connection
if (mysqli_connect_errno())
lessismore是何意{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_select_db($con,"mahmood_faridi");
$query = "SELECT id, name FROM upload";
$result = mysqli_query($con,$query) or die('Error, query failed');mysql无法连接到服务器
if(mysqli_num_rows($result)==0){
echo "Database is empty
";
}
else{
while(list($id, $name) = mysqli_fetch_array($result)){网站设计原理
echo "
";
}
}
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = "SELECT content FROM upload WHERE id = '$id'";
$result = mysqli_query($con,$query) or die('Error, query failed');
$row = mysqli_fetch_row($result);
matlab递归函数$content=$row['content'];
header('Content-type: application/pdf');
c语言入门自学b站header('Content-Disposition: inline; filename="' . $content . '"');
骐骥一跃不能十步驽马十驾header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
ob_clean();
ob_flush();
@readfile($content);
}
mysqli_close($con);
>
这是“保存⽂件”代码:
$con=mysqli_connect("localhost","root","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$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 = mysqli_real_escape_string($con,$content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = mysqli_real_escape_string($con,$fileName);
}
mysqli_select_db($con,"mahmood_faridi");
$query = "INSERT INTO upload (name, size, type, content) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysqli_query($con,$query) or die('Error, query failed');
mysqli_close($con);
echo "
File $fileName uploaded
";
}
else
echo "File not uploaded"
>
+0
你能保存你发送的⽂件吗?什么是⽂件⼤⼩?你确定你的SQL⼯作正常吗? –
+0
查看关于连接。你在这⾥有更多的查询⽐需要的更多 –
+0
SQL⼯作肯定。⽂件⼤⼩为2.05MB,使⽤的数据类型为mediumBlob。不,我也⽆法保存⽂件。 –
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论