鬱悶的問題,rename在foreach中不執行,
當rename($kb,$newfile.$dimg);在foreach外面的時候是執行的,
但是到了foreach裡面就不行了,哪位大神講解下?到底是咋了。怎麼解決!
$hkt=$db->get_one("select fid,attachmentdomain,attachmentdir from news_sort where fid='$fid'");$postdb[content]=str_replace("http://www_mydomain.com","../../".$attachmentdir,$postdb[content]);$newfile="../../upload_files/".$hkt[attachmentdir]."/";preg_match_all("/<[img|IMG].*?src=[\\\'|\\\"][^http](.*?(?:[\.gif|\.jpg]))[\\\'|\\\"].*?[\/]?>/i",$postdb[content],$imglist);foreach($imglist[1] as $kb){$kb=str_replace("\"","",$kb);$dimg=explode("/",$kb);$dimg=$dimg[count($dimg)-1];$kbimg=$hkt[attachmentdomain]."/".$dimg;$postdb[content]=str_replace($kb,$kbimg,$postdb[content]);rename($kb,$newfile.$dimg);unlink($kb);}
回複討論(解決方案)
迴圈中列印出來$kb,$newfile,$dimg等分別是什麼。
要學會一步一步跟蹤調試
均以測試了的!就是在foreach中不行。。 下面的unlink都執行了,就是rename不執行!
迴圈中列印出來$kb,$newfile,$dimg等分別是什麼。
要學會一步一步跟蹤調試
$kb=老的圖片路徑,“../../img/A.jpg”
$newfile=新儲存路徑,"../../newimg/"
$dimg=是圖片的名稱:"a.jpg"
搞定了! 呼呼 ! $newfile不是絕對路徑所致!