Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do so by using the <code>zip://</code> syntax instead of <code>Zip::extractTo</code> as described in the <a href="http://www.php.net/manual/en/function.ziparchive-extractto.php" rel="nofollow">php manual on extractTo()</a>.</p> <p>You have to match the image file name and then copy it:</p> <pre><code>if ($entry['size'] &gt; 0 &amp;&amp; preg_match('#\.(jpg)$#i', $entry['name'])) { copy('zip://' . $file_path . '#' . $entry['name'], '/root_dir/' . md5($entry['name']) . '.jpg'); } </code></pre> <p>The above replaces your for loop's if statement and makes your <code>extractTo</code> unnecessary. I used the md5 hash of the original filename to make a unique name. It is extremely unlikely you will have any issues with overwriting files, since hash collisions are rare. Note that this is a bit heavy duty, and instead you could do <code>str_replace('/.', '', $entry['name'])</code> to make a new, unique filename.</p> <p>Full solution (modified version of your code):</p> <pre><code>&lt;?php $zip = new ZipArchive(); if ($zip-&gt;open($file_path)) { for ($i = 0; $i &lt; $zip-&gt;numFiles; $i++) { $entry = $zip-&gt;statIndex($i); // is it an image? if ($entry['size'] &gt; 0 &amp;&amp; preg_match('#\.(jpg)$#i', $entry['name'])) { # use hash (more expensive, but can be useful depending on what you're doing $new_filename = md5($entry['name']) . '.jpg'; # or str_replace for cheaper, potentially longer name: # $new_filename = str_replace('/.', '', $entry['name']); copy('zip://' . $file_path . '#' . $entry['name'], '/myFolder/' . $new_filename); } } $zip-&gt;close(); } ?&gt; </code></pre>
    singulars
    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.
    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