php - 如何检查图像是否存在于 wodpress 附件中
问题描述
当我上传一个非常小的 50x50px 图像时,它只是作为原始文件(全尺寸)。如何检查图像是否存在。谢谢您的帮助。
if ($image_size == 'thumbnail'):
$image_src = $image['sizes']['thumbnail'];
$image_lazy = $image_src
if ($image_size == 'medium'):
$image_src = $image['sizes']['medium'];
$image_lazy = $image_src;
else:
$image_lazy = $image_src; //oryginal size ???
endif;
解决方案
要检查 PHP 中是否存在文件,Php 已经给了我们函数file_exists(string $filename): bool
<?php
$filename = '/path/to/yourfile.jpg';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
推荐阅读
- javascript - 反应原生
显示错误的值 - reactjs - 如何在 React-Router 中的 Route 标签的路径数组中仅将确切关键字添加到一个路径
- office-addins - Excel 加载项在 PC 上加载最新版本,但在 Excel Online 中不加载
- objective-c - 使用 Kotlin 本机和 ObjectiveC/Swift 的 Optionals/Nullables
- swift - 委托方法,textViewDidChangeSelection 不是每次都触发
- javascript - 试图从javascript中的时间戳数组和价格数组中获取每小时分钟间隔的平均价格
- office-addins - 如何允许我们组织之外的一些用户使用我们的 Excel 加载项
- ruby-on-rails - ActiveStorage Rails 6.1.3 - 我的所有旧图像都收到错误 404 或 500
- leaflet - Esri-leaflet-geocoder:组件未呈现;如何在生产环境中连接供应商
- macos - Intellij 工具窗口“评估表达式”无法打开