开发者

Retrieving and writing a file to system

开发者 https://www.devze.com 2022-12-13 14:01 出处:网络
What\'s the simplest 开发者_开发问答way in PHP, to: Retrieve a file from an external URL (http://test.com/thisfile)?

What's the simplest 开发者_开发问答way in PHP, to:

  1. Retrieve a file from an external URL (http://test.com/thisfile)?

  2. If successful, delete local file /root/xml/test.xml.

  3. Rename downloaded file to test.xml.

  4. Write new file to /root/xml/ folder.

This will be a private script, so security or error handling are not important concerns.


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


Assuming correct configuration,

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

Or something along those lines.

0

精彩评论

暂无评论...
验证码 换一张
取 消