如何在PHP中调整图像大小后获得正确的文件大小?

如何在PHP中调整图像大小后获得正确的文件大小?,php,image,resize,filesize,Php,Image,Resize,Filesize,我有以下代码: // Build the path where I want to save the file; $filePath="uploads/image.jpeg"; /* * Open an input stream relative to $_FILES['file']['tmp_name'] * and write it in an output stream relative to $filePath; */ writeFile($filePath); echo "B

我有以下代码:

// Build the path where I want to save the file;
$filePath="uploads/image.jpeg";
/*
 * Open an input stream relative to $_FILES['file']['tmp_name'] 
 * and write it in an output stream relative to $filePath;
 */
writeFile($filePath);

echo "Before resizing: ".filesize($filePath)." bytes";

/*
 * Create a resized version of the image using imagecopyresampled();
 */
$imageResized = resizeImage($filePath);
/*
 * Actually write the image to the same location of the original;
 */
imagejpeg($imageResized, $filePath);

echo "After resizing: ".filesize($filePath)." bytes";
现在的事实是,ehoes给了我相同的文件大小,而实际上在文件资源管理器中,调整大小后的文件大小要小得多!
调整大小后如何获得正确的文件大小?

请参阅文件大小手册:

注意:此函数的结果将被缓存。有关详细信息,请参阅clearstatcache()。
因此,在第二次文件大小调用之前,请使用clearstatcache()!我忽略了php手册上的注释。另外,我使用
stats($filePath)
insead of
filesize($filePath)
来获取文件大小。