logo
down
shadow

PHP Create Multiple CSV Files in Memory then Compress


PHP Create Multiple CSV Files in Memory then Compress

By : senwebtek
Date : November 21 2020, 01:01 AM
around this issue I have a requirement to create 3 CSV files (in memory) during a single HTTP request, ZIP the files into a single compressed file and return the compressed file as a HTTP response. , Try this...
code :
// some data to be used in the csv files
$headers = array('id', 'name', 'age', 'species');
$records = array(
    array('1', 'gise', '4', 'cat'),
    array('2', 'hek2mgl', '36', 'human')
);

// create your zip file
$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);

// loop to create 3 csv files
for ($i = 0; $i < 3; $i++) {

    // create a temporary file
    $fd = fopen('php://temp/maxmemory:1048576', 'w');
    if (false === $fd) {
        die('Failed to create temporary file');
    }

    // write the data to csv
    fputcsv($fd, $headers);
    foreach($records as $record) {
        fputcsv($fd, $record);
    }

    // return to the start of the stream
    rewind($fd);

    // add the in-memory file to the archive, giving a name
    $zip->addFromString('file-'.$i.'.csv', stream_get_contents($fd) );
    //close the file
    fclose($fd);
}
// close the archive
$zip->close();


header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);

// remove the zip archive
// you could also use the temp file method above for this.
unlink($zipname);


Share : facebook icon twitter icon
Create Zip archive from multiple in memory files in C#

Create Zip archive from multiple in memory files in C#


By : FrankS
Date : March 29 2020, 07:55 AM
With these it helps Use ZipEntry and PutNextEntry() for this. The following shows how to do it for a file, but for an in-memory object just use a MemoryStream
code :
FileStream fZip = File.Create(compressedOutputFile);
ZipOutputStream zipOStream = new ZipOutputStream(fZip);
foreach (FileInfo fi in allfiles)
{
    ZipEntry entry = new ZipEntry((fi.Name));
    zipOStream.PutNextEntry(entry);
    FileStream fs = File.OpenRead(fi.FullName);
    try
    {
        byte[] transferBuffer[1024];
        do
        {
            bytesRead = fs.Read(transferBuffer, 0, transferBuffer.Length);
            zipOStream.Write(transferBuffer, 0, bytesRead);
        }
        while (bytesRead > 0);
    }
    finally
    {
        fs.Close();
    }
}
zipOStream.Finish();
zipOStream.Close();
How to compress multiple files into 3 files per archive with windows batch file?

How to compress multiple files into 3 files per archive with windows batch file?


By : Ken Alverson
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have 100 files that look like this:
code :
@echo off
setlocal enabledelayedexpansion
rem initialize all variables
set counter=1
set groupnumber=1
rem change groupcount value if you want a different number of files per zip
set groupcount=3
set zipfilenamePrefix=archive
rem start looping over...
for %%f in (*) do (
    if not "%%f"=="%~nx0" (
        set fileList=!fileList! %%f
        set /a reminder=!counter!%%!groupcount!
        if !reminder! equ 0 (
            set zipfilename=archive!groupnumber!.tz
            echo Zipping files: !fileList! into !zipfilename!
            rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
            set /a groupnumber=!groupnumber!+1
            set fileList=
        )
        set /a counter=counter+1
    )
)
rem there could be some left over files - last group may be less than 3 files
if !reminder! equ 0 (
    set zipfilename=archive!groupnumber!.tz
    echo Zipping into files: !fileList! !zipfilename!
    rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
)
How to compress multiple files and directories with wix installer and copy and install to other than program files

How to compress multiple files and directories with wix installer and copy and install to other than program files


By : Evan
Date : March 29 2020, 07:55 AM
will help you
How-To: I am against installing to the root, for many technical and practical reasons, but here is a description of how to do it: https://support.firegiant.com/hc/en-us/articles/230912267-Install-to-the-root-of-system-drive-
Is it possible to create multiple files in memory, and then zip them up and write them to disk?

Is it possible to create multiple files in memory, and then zip them up and write them to disk?


By : Flaming Fundament
Date : March 29 2020, 07:55 AM
hope this fix your issue A while ago I implemented a small python library (https://github.com/kajic/vdir) for creating virtual directories, files and even compressing them if need be. From the README (the virtual directory is compressed at the end):
In linux how to archive and compress multiple files into one and remove source files?

In linux how to archive and compress multiple files into one and remove source files?


By : Patrick Smith
Date : March 29 2020, 07:55 AM
I wish this helpful for you You may try pixz which is parallel variant of xz tool (or pxz parallel variant of xz)):
Related Posts Related Posts :
  • how to run wordpress php snippet mysql update command from ssh and/ultimately cron
  • how to get xml tag by name
  • ModSecurity maximum post limits (PCRE limit errors)
  • Call controller/action in event listener
  • How to improve performance of contacting WebService?
  • PHP nest variable in echoed string that contains a HTML tag in the end
  • Multiple Ajax request for PHP framework
  • Debug Info from Moodle Plugin
  • passing variables through page
  • Passing PHP $result data to Javascript
  • cakePHP File Download was not found or not readable
  • batch waiting until script finishes
  • PHP variables and anchors in URL
  • php eTag generation using php
  • How to check whether the array is an Integer or Not?
  • Is it possible to install Doctrine without PEAR or Composer? If so, how?
  • Call view script of (parent) Abstract controller Zend
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org