Read network address Save as file

Source: Internet
Author: User
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");
*/
/***********************************************************/
?>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.