Home > Backend Development > PHP Tutorial > php foreach 执行rename

php foreach 执行rename

WBOY
Release: 2016-06-23 14:16:59
Original
805 people have browsed it

郁闷的问题,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);	}
Copy after login


回复讨论(解决方案)

循环中打印出来$kb,$newfile,$dimg等分别是什么。
要学会一步一步跟踪调试

均以测试了的!就是在foreach中不行。。 下面的unlink都执行了,就是rename不执行!

循环中打印出来$kb,$newfile,$dimg等分别是什么。
要学会一步一步跟踪调试
$kb=老的图片路径,“../../img/A.jpg”
$newfile=新储存路径,"../../newimg/"
$dimg=是图片的名称:"a.jpg"

搞定了! 呼呼 ! $newfile不是绝对路径所致!

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