若成功,则该函数返回 true。若失败,则返回 false。
命令格式为:
bool rename ( string oldname, string newname [, resource context] )
下面演示rename的具体应用,文件位置如图:
实现目的:
1.把cache.txt 更名为rename.txt
2.将cache2.txt更名为cache3.txt
3.将html目录 更名为 cache
4.将file目录转移到html目录下(可以实现更名)
代码如下:
<?php$file = "html/cache.txt"
$rename = "html/rename.txt"
if(rename($file,$rename)){
echo "更名成功"
}else{
echo "更名失败"
}
rename("html/cache2","html/cache3.txt")
rename("html","cache")
rename("file","html/files")
?>
public function downloads(){$file = "./Ludian_Disaster_Relief_Map_Operation_Guide.pdf"
if(file_exists($file)){
header('Content-Description: File Transfer')
header('Content-Type: application/octet-stream')
header('Content-Disposition: attachment filename='.basename($file))
header('Content-Transfer-Encoding: binary')
header('Expires: 0')
header('Cache-Control: must-revalidate, post-check=0, pre-check=0')
header('Pragma: public')
header('Content-Length: ' . filesize($file))
ob_clean()
flush()
readfile($file)
}else{
$this->error("文件不存在")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)