wordpress递归zip文件夹文件下载php/路径问题
我知道关于这个主题有很多代码。但是我找不到有效的代码 我正在使用一个来自Wordpress插件Zip附件的函数。 因此,我将其修改为从特定文件夹压缩文件。但它不起作用 在RecursiveDirectoryIterator类中精确分配路径时,我似乎遗漏了一些东西 我能够压缩单个文件并下载它,而不需要递归迭代功能,也不需要将绝对路径作为字符串传递。因此,函数的主要部分工作正常 我缺少了什么才能使该功能正常工作 这是我的非工作代码:wordpress递归zip文件夹文件下载php/路径问题,php,wordpress,zip,directory,recursive-query,Php,Wordpress,Zip,Directory,Recursive Query,我知道关于这个主题有很多代码。但是我找不到有效的代码 我正在使用一个来自Wordpress插件Zip附件的函数。 因此,我将其修改为从特定文件夹压缩文件。但它不起作用 在RecursiveDirectoryIterator类中精确分配路径时,我似乎遗漏了一些东西 我能够压缩单个文件并下载它,而不需要递归迭代功能,也不需要将绝对路径作为字符串传递。因此,函数的主要部分工作正常 我缺少了什么才能使该功能正常工作 这是我的非工作代码: function za_create_zip_callback()
function za_create_zip_callback(){
$upload_dir = wp_upload_dir();
$rootPath = $upload_dir['basedir'];
$upload_dir_Knippsbox = 'Knippsbox';
// Prepare File
$file = tempnam($upload_dir['path'], "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
// create recursive directory iterator
$files = new RecursiveIteratorIterator (new RecursiveDirectoryIterator("{$rootPath}/{$upload_dir_Knippsbox}/"), RecursiveIteratorIterator::LEAVES_ONLY);
// let's iterate
foreach ($files as $name => $fileX) {
$filePath = $fileX->getRealPath();
$zip->addFile($filePath);
}
//Close the file
$zip->close();
// Add a download to the Counter
global $wpdb;
$meta_name = "_za_counter";
// Retrieve the meta value from the DB
$za_download_count = get_post_meta($postId, $meta_name, true) != '' ? get_post_meta($postId, $meta_name, true) : '0';
$za_download_count = $za_download_count + 1;
// Update the meta value
update_post_meta($postId, $meta_name, $za_download_count);
// We have to return an actual URL, that URL will set the headers to force the download
echo zip_attachments_url."/download.php?za_pretty_filename=".sanitize_file_name($pretty_filename)."&za_real_filename=".$filename;
die();}
拼命寻找你的专家意见。。。
谢谢
本这有什么“不起作用”的?你有错误吗?它能跑吗?如果是的话,它不是拉链吗?问题出在哪里?我认为这是一个错误:解析错误:语法错误,在/mnt/webv/b3/75/56978175/htdocs/WordPress\u SecureMode\u 01/wp content/plugins/zip attachments/zip-attachments.php中出现意外的“/”,然而,这似乎是一个详细的路径问题。如何使用变量指向wp content/upload文件夹中的特定目录?上面代码中的哪一行?(意思是上面代码中的哪一行抛出了错误)?