这应该很容易做到,但我没有任何线索,即使在谷歌了几天。
我已经用PHP创建了一个简单的web表单,允许用户将图像文件上传到服务器,并将日期、文件名(唯一的,上传时自动重命名)等信息输入到MySQL表创建中。
我可以知道如何创建一个链接的‘唯一文件名’上传在MySQL字段显示,以便当用户点击时,它会自动打开服务器存储的文件按唯一的文件名?
如果有人能在这方面帮助我,我将不胜感激。提前谢谢。
发布于 2010-09-02 17:15:08
假设您的表包含字段id、type (MIME类型)和data (二进制数据),这是一个PHP脚本:
<?php //dispimg.php
//example usage: dispimage.php?id=123
$my = new MySQLi('localhost', 'user', 'pass', 'db');
$sql = sprintf('SELECT type, data FROM table WHERE id="%s" LIMIT 1', $my->real_escape_string($id));
if(!$queryResult=$my->query($sql)){
//query failed, log mysqli_error() somewhere
}
elseif(!$queryResult->num_rows){
header('HTTP/1.1 404 Not Found');
echo 'File not found';
}
else($res=$queryResult->fetch_assoc()){
//optionally, use application/octet-stream instead of a field from database
header('Content-Type: '.$res['type']));
// uncomment following line if you want to present the file as download
//header('Content-Disposition: attachment;filename=download');
echo $res['data'];
}
?>https://stackoverflow.com/questions/3625597
复制相似问题