Php 如何从远程FTP服务器上存储的文件在Lavarel中创建ZIP下载?
我需要用FTP从其他主机(子域)中的文件夹创建ZIP文件 我需要从FTP获得下载链接Php 如何从远程FTP服务器上存储的文件在Lavarel中创建ZIP下载?,php,laravel,ftp,laravel-8,laravel-storage,Php,Laravel,Ftp,Laravel 8,Laravel Storage,我需要用FTP从其他主机(子域)中的文件夹创建ZIP文件 我需要从FTP获得下载链接 $id = 1; $zip = new ZipArchive; $fileName = 'myNewFile.zip'; if ($zip->open(storage_path($fileName), ZipArchive::CREATE) === TRUE) { $path = storage_path('/series/sound/' . $id); $files = Storag
$id = 1;
$zip = new ZipArchive;
$fileName = 'myNewFile.zip';
if ($zip->open(storage_path($fileName), ZipArchive::CREATE) === TRUE) {
$path = storage_path('/series/sound/' . $id);
$files = Storage::disk('ftp')->files($path);
foreach ($files as $key => $value) {
$relativeNameInZipFile = basename($value);
$zip->addFile($value, $relativeNameInZipFile);
}
$zip->close();
}
return response()->download(storage_path($fileName));
您必须将文件从FTP下载到web服务器,才能将文件添加到您正在web服务器上创建的ZIP文件中 我不知道拉瓦雷尔,但像这样的事情应该可以:
$contents = Storage::disk('ftp')->get($value);
$zip->addFromString($contents, $relativeNameInZipFile);
这会将文件下载到Web服务器内存中。如果文件太大,这可能不起作用。在这种情况下,您必须将它们下载到web服务器上的临时文件中。hi,运行后显示此错误:
文件“/media/Data/project/storage/myNewFile.zip”不存在
错误此行return response()->下载(存储路径($fileName))代码>打开(存储路径($fileName),ZipArchive::CREATE)的$zip->open(存储路径($fileName)
返回了什么?有反馈吗???