Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd file from string to new folder ZipArchive
    primarykey
    data
    text
    <p>Lets say I have a variable called and instantiated:</p> <p><code>$css = 'body {color:red;}';</code></p> <p>Currently, I'm building my zip file as follows:</p> <pre><code> ini_set("max_execution_time", 300); // create object $zip = new ZipArchive(); // open archive if ($zip-&gt;open("my-archive.zip", ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } // initialize an iterator // pass it the directory to be processed $jsFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../js")); $cssFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../css")); $images = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../_design")); // iterate over the directory // add each file found to the archive foreach ($jsFiles as $key=&gt;$value) { $zip-&gt;addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); } foreach ($cssFiles as $key=&gt;$value) { $zip-&gt;addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); } foreach ($images as $key=&gt;$value) { $zip-&gt;addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key"); } // close and save archive $zip-&gt;close(); echo "Archive created successfully."; </code></pre> <p>Lets say I already have a file called <code>color.css</code> located in <code>/css/main/color.css/</code> and I wanted my new string <code>$css</code> to replace this whole <strong>NEW</strong> file in the <strong>archive</strong>, how could I do that? I had a look at <code>ZipArchive::addFromString</code> but I could not see a way to put that in a certain folder. It's the only file that has to change in my whole directory.</p> <p>Any help would be great.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload