How can PHP be used to retrieve image file size information, specifically width, height, and file size in KB?
To retrieve image file size information in PHP, you can use the `getimagesize()` function which returns an array containing the image width, height, type, and size. To get the file size in KB, you can divide the size in bytes by 1024.
$imagePath = 'path/to/image.jpg';
$imageInfo = getimagesize($imagePath);
$imageWidth = $imageInfo[0];
$imageHeight = $imageInfo[1];
$fileSizeKB = round(filesize($imagePath) / 1024, 2);
echo "Image Width: $imageWidth pixels, Image Height: $imageHeight pixels, File Size: $fileSizeKB KB";
Related Questions
- How can errors be properly handled and logged when running PHP scripts through CronJobs?
- In the provided PHP code snippet, what are some best practices for naming conventions and structuring SQL queries to improve readability and maintainability?
- What are some best practices for handling date and time formats in PHP, especially when dealing with non-standard or non-RFC-compliant formats?