@fwrite 重复写入问题
一个将外部图片下载到服务器空间的程序中有下面这样一段,不过最近发现一个问题,就是每次触发都会重新下载,覆盖之前的文件。添加file_exists不起作用,不知道怎样改成如果目录下已有该图片则跳过呢不执行呢?
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
$t= ".jpg"
$url= "http://....."
$content=@file_get_contents($url);
$path="/home/img/";
$filename=$path.$t;
$fp=fopen($filename,"w+");
if (file_exists($filename)){
if (@fwrite($fp,$content)) //content的内容写入文件指针fp处
{
@fclose($fp);
return $filename;
}
else
{
@fclose($fp);
return false;
}
}
//检测文件是否已经存在 if(file_exists($file)) echo "存在"; else echo "不存在"; <br><font color="#e78608">------解决方案--------------------</font><br> $path="dirname(__FILE__)./home/img/"; <div class="clear"></div>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号