Home > Backend Development > PHP Tutorial > thinkPHP关于修改的问题

thinkPHP关于修改的问题

WBOY
Release: 2016-06-06 20:18:12
Original
1131 people have browsed it

<code>$id=$_GET['id'];        
            $data=$_POST;
            $data['dateandtime']=date("Y-m-d H:i:s");
            $data['content']=str_ireplace('\"','"',$_POST['content']);
            $images=$_FILES['images'];
            if (strlen($images["name"])>0){
                $rs=$news->field("images")->where("id=".$id)->find();
                if (is_file($rs["images"])){
                    unlink($rs["images"]);
                }
                $data['images'] = $this->upFuns1($images);
            }else{
                $rs = $news->field("images")->where("id=".$id)->find();
                $data['images'] = $rs["images"];                
            }    
            $result=$news->where("id=".$id)->save($data);    
            $url=__URL__."/index";
            $str="修改";
            $this->jump($result,$url,$str);
            
        其中    if (is_file($rs["images"])){
                    unlink($rs["images"]);
                }
                这段代码的意思是什么 为什么要这样?
            
            
            </code>
Copy after login
Copy after login

回复内容:

<code>$id=$_GET['id'];        
            $data=$_POST;
            $data['dateandtime']=date("Y-m-d H:i:s");
            $data['content']=str_ireplace('\"','"',$_POST['content']);
            $images=$_FILES['images'];
            if (strlen($images["name"])>0){
                $rs=$news->field("images")->where("id=".$id)->find();
                if (is_file($rs["images"])){
                    unlink($rs["images"]);
                }
                $data['images'] = $this->upFuns1($images);
            }else{
                $rs = $news->field("images")->where("id=".$id)->find();
                $data['images'] = $rs["images"];                
            }    
            $result=$news->where("id=".$id)->save($data);    
            $url=__URL__."/index";
            $str="修改";
            $this->jump($result,$url,$str);
            
        其中    if (is_file($rs["images"])){
                    unlink($rs["images"]);
                }
                这段代码的意思是什么 为什么要这样?
            
            
            </code>
Copy after login
Copy after login

update图片,首先判断这条新闻是否存在图片,is_file是判断文件是否存在,true进入if。
unlink是删除旧图片

判断服务器上是否有同名的文件,如果有的话删除,将新的文件上传

通过id查询是否存在image值,如果存在先删除当前image值,然后update新的image值

Related labels:
php
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