wordpress递归zip文件夹文件下载php /路径问题

时间:2016-02-13 18:50:03

标签: php wordpress zip directory recursive-query

我知道有很多关于该主题的代码。但我无法得到我发现的代码......

我正在使用一个名为Zip-Attachments的Wordpress插件的功能。 所以我将其修改为特定文件夹中的zip文件。但它不起作用....

在准确分配RecursiveDirectoryIterator类中的路径时,似乎我遗漏了一些东西。

我能够压缩单个文件并在没有recursiveIteration功能的情况下下载它并将绝对路径作为字符串传递。因此该功能的主要部分有效。

我缺少什么让这个功能起作用?

这是我的非工作代码:

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();}

拼命寻找您的专家意见...... 谢谢, 本

0 个答案:

没有答案