首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在PHP中调整图像大小后获得正确的文件大小?

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

Stack Overflow用户
提问于 2013-12-13 10:15:19
回答 1查看 640关注 0票数 1

我有这样的代码:

代码语言:javascript
复制
// 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给了我相同的文件大小,而实际上在文件资源管理器中,调整大小后的文件大小要低得多!如何在调整大小后获得正确的文件大小?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-13 10:20:03

请参阅文件大小手册:

注意:这个函数的结果是缓存的。有关更多细节,请参见clearstatcache()。

因此,在第二个文件大小调用之前使用clearstatcache()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20563914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档