Home > Backend Development > PHP Tutorial > thinkphp3.2 uploadify上传 guid在一次上传中只调用一次 怎么实现

thinkphp3.2 uploadify上传 guid在一次上传中只调用一次 怎么实现

WBOY
Release: 2016-06-13 12:10:08
Original
1366 people have browsed it

thinkphp3.2 uploadify上传 guid在一次上传中只调用一次 如何实现?
我想实现的是uploadify上传图片 写入数据库里 自动生成个token 就想到了guid 

上传类用的就是thinkphp本身的 Upload类  结果插入到数据库发现 每个图片都不一样
如下图这样



uploadyify上传后是这样处理的

  public function  uploadify(){<br /><br />        if(!empty($_FILES)){<br /><br />            $config =array(<br />                'maxSize' => 1024000,// 附件大小<br />                'savePath'=> "attachment/picture/uploadify/",//附件保存路径<br />                'saveName'=>array('uniqid',''),//附件保存名称<br />                'exts'=>array('jpg','jpeg','png','gif','rar','zip'),//附件类型<br />                'autoSub'=>true,//开启子目录保存<br />                'subName'=>array('date','Ymd')//子目录命名规则<br /><br />            );<br /><br />            $upload=new \Think\Upload($config);<br /><br /><br /><br />            $files_upload=$upload->upload();<br /><br /><br />            if($files_upload){<br />                foreach($files_upload as $file){<br /><br />//                 $info= $files_upload['Filedate']['savepath'].$files_upload['Filedata']['savename'];<br />//                 上传后文件名<br />                    $savename=$file['savename'];<br />//                 上传前文件名<br />                    $name=$file['name'];<br />//                 上传文件类型<br />                    $type=$file['ext'];<br />//                 上传文件大小 k<br />                    $size=$file['size'];<br />//                 上传目录<br />                    $path=$file['savepath'].$file['subname'].$file['savename'];<br />                  <br />                    $attachment=D('picture_attachment');<br /><br />                    $date['creattime']=date('Y-m-d H:i:s',time());<br />                    $date['pictureurl']=$path;<br />                    $date['oldname']=$name;<br />                    $date['newname']=$savename;<br />                    $date['picturesize']=$size;<br />                    $date['picturetype']=$type;<br />                    $date['pictureid'] =$this->guid();// token guid<br /><br /><br /><br /><br /><br />                   if( $attachment->create($date)){<br />                        $attachment->add();<br />                        session('guid',$date['pictureid']);<br />                   /*   返回给前台JS调用*/<br />                       echo $path ;<br /><br />                   }<br />                    else{<br />                        unlink($path.$type);<br />                        session("FilesInFo",null);<br />                    }<br /><br /><br /><br /><br />                }<br /><br /><br /> ;<br /><br />            }else{<br />                /*返回报错信息*/<br />                $info=$this->error($upload->getError(),U('picture/add'),30);<br />                echo $info;<br />            }<br /><br /><br /><br />        }<br />        else{<br />            echo '上传文件为空';<br />        }<br />// end<br /><br /><br />    }
Copy after login


这样就是遍历上传的文件时候 都生成一次调用  $date['pictureid'] =$this->guid() 这个如何只执行一次  
这样guid多图的 token就一样了~ 求大神指点 具体怎么做啊  麻烦熟悉TP3.2的 大神帮忙了 ~谢谢
------解决思路----------------------
是指这个吗?$date['pictureid'] =$this->guid();// token guid
你在循环里执行,自然每次不一样
你把它放到循环前面去,不就只执行一次了吗?

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