Skip to content

Instantly share code, notes, and snippets.

@dev-4458
Created December 15, 2021 01:24
Show Gist options
  • Select an option

  • Save dev-4458/9f7ff6c4271cd239c22dec2e060920ea to your computer and use it in GitHub Desktop.

Select an option

Save dev-4458/9f7ff6c4271cd239c22dec2e060920ea to your computer and use it in GitHub Desktop.

Revisions

  1. dev-4458 created this gist Dec 15, 2021.
    23 changes: 23 additions & 0 deletions scan_pdf_and_make_zip.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <?php
    //CRON : `/usr/local/bin/ea-php74 /var/www/public_html/scan_pdf_and_make_zip.php 2>&1 | tee /var/www/public_html/scan_pdf.log

    $zip = new ZipArchive;
    $zip->open('/var/www/public_html/zipHavingPDFs.zip', ZipArchive::CREATE);
    $targetFolder = "/var/www/public_html/var/*";

    if(file_exists('/var/www/public_html/zipHavingPDFs.zip')) {
    echo 'zipHavingPDFs file is exiss'.PHP_EOL;
    return;
    }

    foreach (glob($targetFolder) as $file) {
    $ext = pathinfo($file, PATHINFO_EXTENSION);
    if ($ext === 'pdf'){

    //Remove below comment if you want to remove single PDF file
    //$flag = unlink($file);
    file_put_contents('/var/www/public_html/var/log/fd.log', $file.'==='.$flag.PHP_EOL , FILE_APPEND | LOCK_EX);
    $zip->addFile($file);
    }
    }
    $zip->close();