Home > Backend Development > PHP Tutorial > PHP两个文件操作

PHP两个文件操作

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:27:33
Original
1149 people have browsed it

1.获取指定目录下所有文件,包括子文件夹下文件,使用到递归

	function get_all_file($dir){		$files = scandir($dir);		foreach($files as $file){			if($file == '.' || $file == '..') continue;			if(is_file($dir.'/'.$file)){				$res[] = $file;				continue;			}			foreach(get_all_file($dir.'/'.$file) as $ff){				$res[] = $ff;			}		}		return $res;	}
Copy after login

2.获取一个文件相对于另一个文件的相对路径

	//得到$file_2相对$file_1的相对路径	function get_rela_path($file_1,$file_2){		$array_1 = explode('/',$file_1);		$array_2 = explode('/',$file_2);		$deep = count(array_intersect_assoc($array_1,$array_2));				if(count($array_1)-$deep-1 == 0){			$f[] = '.';		}else{			$f = array_fill(0,count($array_1)-$deep-1,'..');		}		$l = array_slice($array_2,$deep);		return implode('/',array_merge($f,$l));	}
Copy after login


====================================================

下面奉上curl的一个demo

curl主要是curl_setopt中curlopt_*的理解和活用

比较常用的也就是下面这几个了,查查手册,搞清楚吧

	function getUrl($url){				$ch = curl_init();		$data = array('name'=>'zhaozonglu','age'=>21);		curl_setopt($ch,CURLOPT_URL,$url);		curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);		curl_setopt($ch,CURLOPT_FAILONERROR,true);		curl_setopt($ch,CURLOPT_POST,true);		curl_setopt($ch,CURLOPT_POSTFIELDS,$data);		$out = curl_exec($ch);		$info = curl_getinfo($ch,CURLINFO_HTTP_CODE);		curl_close($ch);		return $info;			}
Copy after login



版权声明:本文为博主原创文章,未经博主允许不得转载。

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