Home >Backend Development >PHP Tutorial >@fwrite 重复写入有关问题

@fwrite 重复写入有关问题

WBOY
WBOYOriginal
2016-06-13 10:13:44972browse

@fwrite 重复写入问题
一个将外部图片下载到服务器空间的程序中有下面这样一段,不过最近发现一个问题,就是每次触发都会重新下载,覆盖之前的文件。添加file_exists不起作用,不知道怎样改成如果目录下已有该图片则跳过呢不执行呢?

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$t= ".jpg"$url= "http://....."[email protected]_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 "不存在";<br><font color="#e78608">------解决方案--------------------</font><br>$path="dirname(__FILE__)./home/img/";<div class="clear">
                 
              
              
        
            </div>
Statement:
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