如何进行绝对 MySQL 查询匹配。因为如果用户试图通过短链接 domain.ltd/NGV 调用 url 或文件,这与 domain.ltd/ngv 冲突,我似乎会发生冲突,从而强制提取脚本提取 /NGV 文件而不是 /ngv
这是执行 MySQL 选择的代码,还提供了 htaccess 位
$tag = $_REQUEST['rid'];
$q = mysql_query("SELECT * FROM `media` WHERE `qp_tag` = '".mysql_escape_string($tag)."' LIMIT 1");
$r = mysql_fetch_row($q);
if(!empty($r)) {
$f = stripslashes($r['file']);
$t = stripslashes($r['type']);
$c = file_get_contents($f);
$api_html = <<<API_HTML_VIEW
$c
API_HTML_VIEW;
echo $api_html;
} else {
$api_html = <<<API_HTML_VIEW
We are sorry but we cannot find requested resource :(
API_HTML_VIEW;
echo $api_html;
}
.htaccess 代码位
RewriteRule ^([a-zA-Z0-9-]+)/?$ api.php?rid=$1 [L,QSA]
这是生成实际短链接的最后一段代码,这也可能是问题所在,因为我不确定现在是什么让事情退缩
function qp_tag() {
$file_tag = $_FILES['file']['name'];
$file_uni = uniqid();
$short = strtolower(substr(base64_encode(crc32($file_tag)), 0, 3));
return $short;
}
已编辑:系统现在可以工作,唯一的问题是,如果它是一个文件,它会滞后于选择文件
$f = $r['file'];
$t = $r['type'];
$s = $r['size'];
$n = $r['name'];
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: ".$t."");
header("Content-Disposition:attachment;filename=".$n."");
header("Content-Length: ".$s);
ob_clean();
flush();
$fp = fopen($f, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);