Javascript PHP-将textarea内容作为html添加到zip

Javascript PHP-将textarea内容作为html添加到zip,javascript,php,html,zip,Javascript,Php,Html,Zip,我正在开发一个内部应用程序,用户上传一些图像,使用它们,最后将所有文件作为一个包下载 我是一个真正的PHP初学者,所以我找到了一个创建上传图像zip的代码 <?php $dir = 'uploads/'; $zip_file = 'file.zip'; // Get real path for our folder $rootPath = realpath($dir); // Initialize archive object $zip = new ZipArchive(); $zi

我正在开发一个内部应用程序,用户上传一些图像,使用它们,最后将所有文件作为一个包下载

我是一个真正的PHP初学者,所以我找到了一个创建上传图像zip的代码

<?php

$dir = 'uploads/';
$zip_file = 'file.zip';

// Get real path for our folder
$rootPath = realpath($dir);

// Initialize archive object
$zip = new ZipArchive();
$zip->open($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE);

// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($rootPath),
    RecursiveIteratorIterator::LEAVES_ONLY
);

foreach ($files as $name => $file)
{
    // Skip directories (they would be added automatically)
    if (!$file->isDir())
    {
        // Get real and relative path for current file
        $filePath = $file->getRealPath();
        $relativePath = substr($filePath, strlen($rootPath) + 1);

        // Add current file to archive
        $zip->addFile($filePath, $relativePath);
    }
}

// Zip archive will be created only after closing object
$zip->close();


header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($zip_file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($zip_file));
readfile($zip_file);

?>
现在有一个文本区域有一个代码


我想将textarea的内容作为html添加到zip中。

您应该将textarea的内容保存为$dir='uploads/';中的separated.html文件;。为此,您可以使用file\u put\u contents方法记住正确的文件路径。创建ZIP后,您可以删除此文件

那么,是什么阻止了你创建html文件呢?谢谢你的回复,事实上,我通过一点研究就解决了这个问题。我用了addFromString。现在我想做的是在我的zip命名资产中创建一个文件夹,它将包含所有图像&在根目录上,它已经包含index.html。file.zip-assets img1.jpg index.html