1

刚开始,我是一个 PHP 菜鸟。

我有一个托管我的文件的 Apache 服务器。我有一台只能指向一个 PHP 文件的设备。我需要它做的是让我的 PHP 文件以我要下载的文件的名称读取,并将其指向它存储的目录。目前,我让它指向一个文件,但我需要它能够指向多个文件。这在PHP中可能吗?

这是我到目前为止所拥有的:

<?php 
$file_name = 'file.img';
$size = filesize($file_name);
$file_url = 'http://192.168.0.5/' . $file_name;
header("Content-length: $size");
header("Content-Type: text/plain");
header("Content-Transfer-Encoding: binary");
header("Content-disposition: attachment; filename=\"".$file_name."\"");
readfile($file_url);?>

编辑:我要输入以下载文件的命令足够接近如下:

cmd=download+-a+$$.img+altimage
cmd=download+-a+$$.conf+altconfig

下载目录是 .php 文件。我对如何做到这一点的其他建议持开放态度。

Edit2:这是一个确切的示例 URL:

 myserver.com/cgi-bin/va/cmd?hdl+fullconfig.ini+altconfig

hdl 是一个预定义的函数,它指向下载目录,以便从服务器下载文件,所以你的意思的布局并不完全相同。

4

1 回答 1

0

我很难理解您到底要做什么,但我想您希望用户能够下载多个文件。如果这是正确的,这是实现此目的的一种方法:

您可以让 PHP 使用ZIP 扩展名创建一个 ZIP 存档。为了让它工作,你必须在你的 php.ini 中加载扩展 php_zip.dll。

$ZIP = new ZipArchive();

// Use the current time as the filename to prevent two users to use the same file
$ZIPName = microtime().".zip";

// Create a new ZIP file
$ZIP->open($ZIPName, ZIPARCHIVE::CREATE);

// Loop through all files - $Files needs to be an array with the names of the files you want to add, including the paths
// basename() will prevent the creation of folders inside the ZIP
foreach ($Files as $File) {
    $ZIP->addFile($File, basename($File));
}

// Close the archive
$ZIP->close();

// Send the archive to the browser
readfile($ZIPName);

我希望这就是你要找的。

于 2013-02-28T11:54:13.203 回答