Internet
<?php
function create_html ($save _path, $file _name, $read _file)
{
Read the file and write to a file
Author:wjjchen
$save _path: To save the path, Unix style, and finally add "/";
$file _name: file name to save
$read _file: A file or URL read
/* About return values
-1: No directory permissions created
-2: No permissions to read files or no files or read any content
-3: Write file Error
-4: File not writable
1: Execution success
*/
$path _array = Explode ("/", $save _path);
foreach ($path _array as $path)
{
if ($path)
{
$now _path. = $path. " /";
if (!is_dir ($now _path))
{
if (!mkdir ($now _path))
{
No directory permissions were created, exiting.
return-1;
Exit ();
}
}
}
}
Reading files
$contents = @file_get_contents ($read _file);
if (! $contents)
{
No permissions to read files or no files or read anything
Return-2;
Exit ();
}else
{
Write to File
$handle = @fopen ($save _path $file _name, "w+");
if ($handle)
{
if (@fwrite ($handle, $contents))
{
return 1;
}else
{
Write file Error
return-3;
}
}else
{
File not writable
return-4;
}
}
End FUNCTION
}
/******************************** Sample ************************/
/*
Absolute path
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");
Relative path
Echo create_html ("./adf/asfd/", "3.html", "http://www.xrss.cn");
*/
/***********************************************************/
?>