Skip to content

Instantly share code, notes, and snippets.

View alexsegura's full-sized avatar
🔥
On fire

Alexandre Segura alexsegura

🔥
On fire
View GitHub Profile
@alexsegura
alexsegura / gist:7357978
Last active December 27, 2015 16:49
Simple function to add an entire folder to a ZipArchive. Uses getSubPathName to avoid recreating whole disk structure. Uses iterators, no recursion.
<?php
function addFolderToZip(\ZipArchive $zip, $dir) {
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST);
$zip->addEmptyDir(basename($dir));
@alexsegura
alexsegura / csv.php
Created June 26, 2012 13:06
Simple HTML form to create CSV files with PHP
<?php
if (isset($_POST['rows'])) {
$h = tmpfile();
foreach ($_POST['rows'] as $row) {
fputcsv($h, array_values($row));
}
rewind($h);
$csv = '';