【发布时间】:2015-09-03 15:06:15
【问题描述】:
很多天前,我读过this question。然后,我尝试了这段代码:
$code = $_GET['code'];
$str_1 = mysql_query("SELECT * FROM `MyTable`");
while ($str_2 = mysql_fetch_array($str_1)) {
header("content-type: application/octet-stream");
header("content-disposition: inline; filename= " . $str_2['my_id'] . "");
echo base64_decode($str_2['my_str']);
}
我的我的数据库,有一些数据:
+--------+-----------------+
| my_id | my_str |
+--------+-----------------+
| id_1 | base64_str_1 |
| id_2 | base64_str_2 |
| id_3 | base64_str_3 |
| id_4 | base64_str_4 |
+--------+-----------------+
当我用浏览器浏览我的 PHP 代码时,例如:http://localhost/my_php.php?code=id_3。它总是返回一个满足的文件(名为:id_3)(它的内容:base64_str_1)。
你能告诉我:“这个 PHP 代码有什么问题,带有 SQL 查询吗?”。
【问题讨论】:
-
为什么要循环发送
headers?只是为了了解正在发生的事情,尝试用简单的echo替换header。并先阅读一些关于标题的文章 -
您没有在 Select 语句中使用 WHERE my_id=$code