Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法检查wordpress媒体是否真的存在?_Wordpress_Gallery - Fatal编程技术网

有没有办法检查wordpress媒体是否真的存在?

有没有办法检查wordpress媒体是否真的存在?,wordpress,gallery,Wordpress,Gallery,我有几个wordpress网站,我正在使用批量媒体上传(我自己的脚本)。 但有时,由于服务器问题或图像问题,上载失败。 我不想重播这些图片,但我不想它们也存在于我的媒体库中。 我试过wordpress断开链接检查插件,但它在post中的嵌入式媒体中工作,但在嵌入式库中不工作。 那么,有没有办法检查媒体文件是否确实存在并删除损坏的文件? 谢谢。您可以使用WP图像编辑器检查、尝试: $image = wp_get_image_editor( 'my_image.jpg' ); if (is_wp_e

我有几个wordpress网站,我正在使用批量媒体上传(我自己的脚本)。 但有时,由于服务器问题或图像问题,上载失败。 我不想重播这些图片,但我不想它们也存在于我的媒体库中。 我试过wordpress断开链接检查插件,但它在post中的嵌入式媒体中工作,但在嵌入式库中不工作。 那么,有没有办法检查媒体文件是否确实存在并删除损坏的文件?
谢谢。

您可以使用WP图像编辑器检查、尝试:

$image = wp_get_image_editor( 'my_image.jpg' );
if (is_wp_error($image)){
  //do some action, like add image path and name to array of broken images
}

感谢您的回答,它看起来很有用,但我如何检查整个uploads文件夹?最好的办法是使用上传过程中生成的列表(这样您就有机会发现丢失的文件)。如果不可能,请使用以下脚本循环浏览所有文件: