Skip to content

Instantly share code, notes, and snippets.

@braytac
Created August 22, 2020 05:39
Show Gist options
  • Save braytac/626c42596eac7ef46295cf3a2b35cdfc to your computer and use it in GitHub Desktop.
Save braytac/626c42596eac7ef46295cf3a2b35cdfc to your computer and use it in GitHub Desktop.
gen txt list for montpres pdf.php
<?php
function human_filesize($bytes, $decimals = 1) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
$folder = "/home/webs/montpres/wp-content/uploads/molt_psp_familias_completas";
$genlist = "/home/webs/montpres/wp-content/pdf_generados.txt";
$listado = array();
$iterator = new DirectoryIterator( $folder );
foreach ($iterator as $fileinfo) {
if ( strtolower($fileinfo->getExtension()) == "pdf") {
$dat = date("Y-m-d H:i", $fileinfo->getMTime());
$size = human_filesize( $fileinfo->getSize());
$listado[$dat] = "1 ".$size." ".$dat." ".$fileinfo->getFilename()."\n" ;
}
}
ksort($listado);
$listado = array_reverse($listado);
file_put_contents($genlist, implode($listado));
?>
@braytac
Copy link
Author

braytac commented Aug 26, 2020

Antes con bash:
#!/bin/bash

echo "Generando Listado...";
ls -laGght --time-style=long-iso
/home/webs/montpres/wp-content/uploads/molt_psp_familias_completas
| sed -re 's/^[^ ]* //'
| grep ".pdf" --color=never \

/home/webs/montpres/wp-content/pdf_generados.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment