<div class="cnblogs_code">
</span><span style="color: #800080;">$num</span> = 50<span style="color: #000000;">;
</span><span style="color: #800080;">$p</span> = <span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->request->get['p'])?<span style="color: #800080;">$this</span>->request->get['p']:0<span style="color: #000000;">;
</span><span style="color: #800080;">$nonum</span> = <span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->request->get['nonum'])?<span style="color: #800080;">$this</span>->request->get['nonum']:0<span style="color: #000000;">;
</span><span style="color: #800080;">$start</span> = (<span style="color: #800080;">$nonum</span>>0)?<span style="color: #800080;">$nonum</span>:<span style="color: #800080;">$p</span>*<span style="color: #800080;">$num</span><span style="color: #000000;">;
</span><span style="color: #800080;">$query</span> = <span style="color: #800080;">$this</span>->db->query("SELECT product_id,image,site_id FROM " . DB_PREFIX . "product WHERE is_delete = 0 AND site_id='2170254929593344' AND image LIKE '%.alicdn.com%' LIMIT ".<span style="color: #800080;">$start</span>.",".<span style="color: #800080;">$num</span><span style="color: #000000;">);
</span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$query</span>-><span style="color: #000000;">rows;
</span><span style="color: #008000;">//</span><span style="color: #008000;"><a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>处理</span>
<span style="color: #0000ff;">if</span>(!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span><span style="color: #000000;">)){
</span><span style="color: #800080;">$aliYunOSS</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> AliYunOSS();
</span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$result</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">){
</span><span style="color: #800080;">$file</span> = <span style="color: #800080;">$value</span>['image'<span style="color: #000000;">];
</span><span style="color: #008000;">//</span><span style="color: #008000;">保存<a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>到服务器上</span>
<span style="color: #800080;">$data</span> = @<span style="color: #008080;">file_get_contents</span>(<span style="color: #800080;">$file</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">if</span>(!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$data</span><span style="color: #000000;">)){
</span><span style="color: #800080;">$ext</span> = <span style="color: #008080;">pathinfo</span>(<span style="color: #800080;">$file</span>,<span style="color: #000000;"> PATHINFO_EXTENSION);
</span><span style="color: #800080;">$filename</span> = <span style="color: #800080;">$value</span>['product_id'].<span style="color: #008080;">rand</span>(). '.' . <span style="color: #800080;">$ext</span><span style="color: #000000;">;
</span><span style="color: #800080;">$rootFile</span> = DIR_UPLOAD .'file/'. <span style="color: #800080;">$filename</span><span style="color: #000000;">;
</span><span style="color: #008080;">file_put_contents</span>(<span style="color: #800080;">$rootFile</span>,<span style="color: #800080;">$data</span><span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"><a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a><a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>到阿里云</span>
<span style="color: #800080;">$fileDir</span> = <span style="color: #008080;">date</span>('Y',<span style="color: #008080;">time</span>()) . '/' . <span style="color: #008080;">date</span>('m',<span style="color: #008080;">time</span><span style="color: #000000;">());
</span><span style="color: #800080;">$ali</span> = <span style="color: #800080;">$aliYunOSS</span>->uploadFile(<span style="color: #800080;">$rootFile</span>,<span style="color: #800080;">$value</span>['site_id'].'/'.<span style="color: #800080;">$fileDir</span>.'/'.<span style="color: #800080;">$filename</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$ali</span>['success']==1 && !<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$ali</span>['info']['url'<span style="color: #000000;">])){
</span><span style="color: #800080;">$image</span> = <span style="color: #800080;">$ali</span>['info']['url'<span style="color: #000000;">];
</span><span style="color: #0000ff;">if</span> (ENVIRONMENT == 'pro'<span style="color: #000000;">) {
</span><span style="color: #800080;">$image</span> = <span style="color: #008080;">str_replace</span>('http://joinf-website-release.oss-cn-hongkong.aliyuncs.com',OSS_URL,<span style="color: #800080;">$image</span><span style="color: #000000;">);
</span><span style="color: #800080;">$image</span> = <span style="color: #008080;">str_replace</span>('https://joinf-website-release.oss-cn-hongkong.aliyuncs.com',<span style="color: #800080;">$image</span><span style="color: #000000;">);
}
</span><span style="color: #800080;">$<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a></span> = "UPDATE " . DB_PREFIX . "product SET image='".<span style="color: #800080;">$image</span>."' WHERE product_id='".<span style="color: #800080;">$value</span>['product_id']."' AND image='".<span style="color: #800080;">$value</span>['image']."'"<span style="color: #000000;">;
</span><span style="color: #800080;">$this</span>->db->query(<span style="color: #800080;">$<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a></span><span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"><a href="https://www.jb51.cc/tag/shanchu/" target="_blank" class="keywords">删除</a>服务器<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a></span>
<span style="color: #008080;">unlink</span>(<span style="color: #800080;">$rootFile</span><span style="color: #000000;">);
}
}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
</span><span style="color: #800080;">$nonum</span>++<span style="color: #000000;">;
}
}
</span><span style="color: #800080;">$url</span> = <span style="color: #800080;">$this</span>->url->createUrl('test/transferImage','p='.(<span style="color: #800080;">$p</span>+1).'&nonum='.<span style="color: #800080;">$nonum</span>.'&rand='.<span style="color: #008080;">rand</span>(1000,9999<span style="color: #000000;">));
</span><span style="color: #0000ff;">echo</span> "<script>window.location.href='".<span style="color: #800080;">$url</span>."'</script>"<span style="color: #000000;">;
}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{
</span><span style="color: #0000ff;">echo</span> '处理完成'<span style="color: #000000;">;
}
}</span></pre>