Retrieving and writing a file to system

What's the simplest way in PHP, to:

  1. Retrieve a file from an external URL (
  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( '' );
if( $contents ) {
$file = '/root/xml/test.xml';
unlink( $file );
file_put_contents( $contents, $file );

Assuming correct configuration,

$file = file_get_contents('');
if($file) {

Or something along those lines.

Category:php Time:2009-12-02 Views:1
Tags: php file file io

Related post

Copyright (C), All Rights Reserved.

processed in 3.467 (s). 13 q(s)