Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我可以下载的SQL数据库中我的项目的$path是什么?_Php_Mysql - Fatal编程技术网

Php 我可以下载的SQL数据库中我的项目的$path是什么?

Php 我可以下载的SQL数据库中我的项目的$path是什么?,php,mysql,Php,Mysql,我找到了一些帖子,解释了如何从PHP中的SQL数据库下载文件(在我的例子中是MP3)。显然,文件的$path是启用下载所必需的。我有MP3上传到我的数据库,但没有上传路径,因为我不知道它会是什么。我习惯于通过关联数组访问对象,例如:$row['wholeMP3'];该项以longblob形式存储在数据库中。我不明白我的$path将是什么。如果有人能进一步向我解释,我们将不胜感激 <?php query2 = "SELECT* FROM MP3s_for_Sale WHERE id = :i

我找到了一些帖子,解释了如何从PHP中的SQL数据库下载文件(在我的例子中是MP3)。显然,文件的$path是启用下载所必需的。我有MP3上传到我的数据库,但没有上传路径,因为我不知道它会是什么。我习惯于通过关联数组访问对象,例如:$row['wholeMP3'];该项以longblob形式存储在数据库中。我不明白我的$path将是什么。如果有人能进一步向我解释,我们将不胜感激

<?php
query2 = "SELECT* FROM MP3s_for_Sale WHERE id = :itemNum";
$LastProduct = $db->prepare($query2);
$LastProduct->bindvalue(':itemNum', $itemNum);
$LastProduct->execute();
//Need to figure out how to download
$rows = $LastProduct->fetchAll();
$LastProduct->closeCursor();
foreach ($rows as $row){
// I have created a column for the filename and extension called path
$filename = $row['path'];
$filesize = $row['filesize'];

//$size = filesize($yourfile);
//echo "size ".$size;
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename='$filename'");
header("Content-Length: $filesize");
//what is $yourfile?
//readfile($yourfile);
//I put this here and it does transfer a file just not operable
echo $row['wholeMP3']; 
} 
?>

没有路,伙计。您需要直接发送二进制blob。请您进一步解释。我看到的代码需要$yourfile作为路径。我不知道如何下载的其他方法。我猜您在数据库中存储了一个“路径”,并将文件上载到服务器。这意味着使用select,您所需要做的就是从db获取文件路径,并且文件应该download@SuperDJ该问题明确指出“该项在数据库中存储为长blob”。如果
$row['wholeMP3']
是一个文件名,那么这个代码会很好地工作。但是我确实需要大小。我想我可以在上传中找到它并将其存储在表中,对吗?
$query2 = "SELECT* FROM MP3s_for_Sale WHERE id = :itemNum";
$LastProduct = $db->prepare($query2);
$LastProduct->bindvalue(':itemNum', $itemNum);
$LastProduct->execute();
//Need to figure out how to download
$rows = $LastProduct->fetchAll();
$LastProduct->closeCursor();
foreach ($rows as $row){
$filename = $row['path'];
$filesize = $row['filesize'];
$content =  $row['wholeMP3'];
$type = $row['type']; 

header("Content-length: $filesize");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$filename");
ob_clean();
flush();
echo $content;
}
exit;