简体   繁体   中英

Determine if a PDF is Corrupt

How can I determine if a PDF file is corrupt (not openable) in PHP? I have downloaded thousands of PDFs via CURL and a small number are incomplete.

$part = 'pdffile.pdf';
$escPath = str_replace( " ", "\\ ", escapeshellcmd( $part ) );
$out = shell_exec( 'pdfinfo ' . $escPath . ' 2>&1' );
if( $out != null && !preg_match( '~Error~i', $out ) )
    echo "GOOD: $part\n";
else
    echo "CORRUPT: $part\n";

I can only find a way to do this via the command line. The second line is required to escape file paths.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM