如何将"Ficheiro"的echo与下载"Fichero"文件名的脚本链接?
来自"Ficheiro"的示例回波将类似于1509071717-de_dust2.dem
如何从ftp下载此文件?
Ftp:ftp://USER:PASSWORD@IPHOST:端口/
代码:
<?php
require('config.php');
$iConnection = mysqli_connect($_HOST_,$_USER_,$_PASS_,$_MYDB_) or die("<link rel='stylesheet' type='text/css' href='css/style.css'><h4>Rank not found.</h4>");
?>
<html>
<body>
<table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<th>FICHEIRO</th>
</tr>
<?php
$sql = "SELECT * FROM HLTV1 ORDER BY Ficheiro DESC";
$iResult = mysqli_query($iConnection, $sql);
while($Row = mysqli_fetch_array($iResult))
echo "<td style='text-align: center;' width='5%'>" . $Row['Ficheiro'] . "</td>";
echo "</tr>";
mysqli_close($iConnection);
?>
</table>
</body>
</html>
如果您不关心清除ftp用户名/密码,您可以简单地将
echo "<td style='...'><a href='ftp://USER:PASSWORD@UPHOST:port/" . $Row['Fichieiro'] . "'>" . $Row['Fichieiro'] . "</a></td>";
如果你想隐藏,你必须创建一个单独的脚本,从FTP下载文件并直接输出给用户下载。看看这里的例子(用ftp代替http(。请注意,这假设您的PHP.ini中有allow_url_fopen
和相关版本。另一个版本将使用curl
(同样,您必须安装并启用它(。
这里有一个例子:
echo "<td style='...'><a href='donwload.php?file=" . $Row['Fichieiro'] . "'>" . $Row['Fichieiro'] . "</td>";
在download.php
文件中,您可能有:
$file = (!empty($_GET['file']) ? $_GET['file'] : null);
if($file) {
try {
$fp = fopen('ftp://USER:PASSWORD@UPHOST:port/' . $file, 'rb');
// send the right headers
header("Content-Type: application/x-download");
header('Content-Disposition: attachment; filename="' . $file . '"');
// Dump the file directly
fpassthru($fp);
// exit to avoid some extra spaces in output
exit;
} catch ('Exception $ex) {
echo "Error, file not found (most probably)";
}
}
echo "Error, no file specified";
通过这种方式,用户唯一看到的就是文件名。为了简单起见,我在这里使用fpassthrough,但您可以使用fopen
、fread
、,CCD_ 6和CCD_。有关这些函数的示例,请查看此处。
希望能有所帮助。