2009-12-02 79 views
1

什么是PHP中最简单的方法,来:检索和写入文件系统

  1. 检索从外部URL(http://test.com/thisfile)的文件?

  2. 如果成功,删除本地文件/root/xml/test.xml

  3. 将下载的文件重命名为test.xml

  4. 将新文件写入/root/xml/文件夹。

这将是一个私人的脚本,所以安全性或错误处理并不重要顾虑。

回答

3
$contents = file_get_contents('http://test.com/testfile'); 
if($contents) { 
    $file = '/root/xml/test.xml'; 
    unlink($file); 
    file_put_contents($contents, $file); 
} 
3

假设正确的配置,

$file = file_get_contents('http://test.com/thisfile'); 
if($file) { 
    unlink('/root/xml/test.xml'); 
    file_put_contents('/root/xml/test.xml'); 
} 

或者类似的规定。