您好,欢迎访问一九零五行业门户网

@fwrite 重复写入有关问题

@fwrite 重复写入问题
一个将外部图片下载到服务器空间的程序中有下面这样一段,不过最近发现一个问题,就是每次触发都会重新下载,覆盖之前的文件。添加file_exists不起作用,不知道怎样改成如果目录下已有该图片则跳过呢不执行呢?
php code$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;}}
------解决方案--------------------
php code//检测文件是否已经存在if(file_exists($file)) echo 存在;else echo 不存在;
------解决方案--------------------
$path=dirname(__file__)./home/img/;

其它类似信息

推荐信息