網路
<?php
function create_html($save_path,$file_name,$read_file)
{
//讀取檔案然後寫入到一個檔案
//Author:wjjchen
//$save_path:要儲存的路徑,UNIX風格,最後加"/";
//$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");
*/
/***********************************************************/
?>