Created
December 15, 2021 01:24
-
-
Save dev-4458/9f7ff6c4271cd239c22dec2e060920ea to your computer and use it in GitHub Desktop.
PHP script that will scan all the PDF files from particular directory and make a zip, un-link individual PDF file as well
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment