显示和下载数据库blob中的数据

时间:2018-01-18 15:06:30

标签: php mysql blob

我有这个脚本将文件插入数据库blob类型。 我可以看到文件名,但我无法打开/下载文件 你可以看到我尝试了回声,但似乎它没有开始下载文件

<form method="post" enctype="multipart/form-data" >
 <input type="file" name="myfile"/>
 <button name="btns"> Incarca Schita </button>
 </form>
 <?php
 $dbh = new PDO("mysql:host=localhost;dbname=highmob_comenzi", "highmob", "PW");
 if(isset($_POST['btns'])){
     $name = $_FILES['myfile']['name'];
     $type = $_FILES['myfile']['type'];
     $data = file_get_contents($_FILES['myfile']['tmp_name']);
     $stmt = $dbh->prepare("UPDATE players SET data='$myfile', name='$name', mime='$type' WHERE id='$id'");
     $stmt->bindParam(1,$name);
     $stmt->bindParam(2,$type);
     $stmt->bindParam(3,$data);
     $stmt->execute();
 }
 ?>
 <?php
 $stat = $dbh->prepare("select * from players where id='$id'");
 $stat->execute();
 while($row = $stat->fetch()){
     echo "<a href='".$row['data']."'>".$row['name']."</a>
     ";
 }
 ?>

0 个答案:

没有答案