Home > Backend Development > PHP Tutorial > PHP怎么判断多张图片文件名,并返回缺少哪张图片

PHP怎么判断多张图片文件名,并返回缺少哪张图片

WBOY
Release: 2016-06-13 12:25:54
Original
982 people have browsed it

PHP如何判断多张图片文件名,并返回缺少哪张图片?
各位大神 求救 如何实现 例如 有个字段列表存了(‘1.jpg’,‘2.jpg’,‘3.jpg’);
怎么实现判断他与数据库中存放的图片字段是否一样 并把数据库缺少的图片名字返回  
php代码怎么实现   数据库存的是一个字段存多张图片。。。
------解决思路----------------------
读取字段内容,解析出图片名
配好路径,在循环中用 file_exists 函数进行检查
------解决思路----------------------
首先读出数据库内容。分解成数组,然后遍历,判断文件是否存在。

<br /><?php<br />$arr = array('1.jpg','2.jpg','3.jpg');<br />$notexists = array();<br />foreach($arr as $k=>$v){<br />    if(!file_exists($v)){<br />        $notexists[] = $v;<br />    }<br />}<br />print_r($notexists);<br />?><br />
Copy after login

------解决思路----------------------
<br /><?php<br />$folder = '/home/fdipzone/xxx/'; // 指定的文件夹<br />$arr = array('1.jpg','2.jpg','3.jpg');<br />$notexists = array();<br />foreach($arr as $k=>$v){<br />    if(!file_exists($folder.$v)){<br />        $notexists[] = $v;<br />    }<br />}<br />print_r($notexists);<br />?><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template