PHP Get File Information

Posted Under: PHP, Programming, Snippets on Feb 27, 2020
PHP Code snippet to get Information about a file such as File Name, File Extension, File Size, File MIME Type, File Complete Path.


$file = new SplFileObject($tragetFile);
$finfo = new finfo(FILEINFO_MIME);

echo "File Name with Extension: ".$file->getFilename();
echo "

"; echo "File Extension: ".$file->getExtension(); echo "

"; echo "File Name without Extension: ".substr($file->getFilename(), 0, (strlen($file->getExtension())>0?(-1* strlen($file->getExtension())-1):strlen($file->getFilename()))); echo "

"; echo "File Path: ".$file->getPath(); echo "

"; echo "File Size (Bytes): ".$file->getSize(); echo "

"; echo "File MIME Type With encoding: ".$finfo->file($tragetFile); ?>

© Tutorial Jinni