php foreach 執行rename

來源:互聯網
上載者:User
鬱悶的問題,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不是絕對路徑所致!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.