function create_html($save_path,$file_name,$read_file)
{
//读取文件然后写入到一个文件
//Author:wjjchen
//$save_path:要保存的路径,UNIX风格,最后加"/";
http://www.gaodaima.com/46610.html读取网络地址保存为文件_php
//$file_name:要保存的文件名
//$read_file:读取的文件或者URL
/*关于返回值
-1:没有创建目录权限
-2:没有权限读取文件或者没有此文件或者没有读取到任何内容
-3:写入文件错误
-4:文件不可写
1:执行成功
*/
$path_array = explode("/",$save_path);
foreach ($path_array as $path)
{
if ($path)
{
$now_path .= $path."/";
if (!is_dir($now_path))
{
if (!mkdir($now_path))
{
//没有创建目录权限,退出。
return -1;
exit();
}
}
}
}
//读取文件
$contents = @file_get_contents($read_file);
if (!$contents)
{
//没有权限读取文件或者没有此文件或者没有读取到任何内容
return -2;
exit();
}else
{
//写入文件
$handle = @fopen($save_path.$file_name,"w+");
if ($handle)
{
if (@fwrite($handle,$contents))
{
return 1;
}else
{
//写入文件错误
return -3;
}
}else
{
//文件不可写
return -4;
}
}
//END FUNCTION
}
/********************************示例************************/
/*
绝对路径
echo create_html("e:/af/asdf/","1.html","http://www.pclala.com");
echo create_html("e:/af/asdf/","2.html","e:/af/asdf/1.html");
相对路径
echo create_html("./adf/asfd/","3.html","http://www.xrss.cn");
*/
/***********************************************************/
?>
欢迎大家阅读《读取网络地址保存为文件_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码
原创文章,转载请注明: 转载自搞代码
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~