Follow me on Twitter Facebook Flickr Subscribe Feeds
 

Copiare un file esterno sul nostro sito

This entry was posted on October 21st, 2008 and is filed under php.

Lo script in questo articolo risulta molto comodo quanto abbiamo bisogno di prelevare da un sito esterno un particolare documento per poi salvarlo sul nostro server.


<?php
// this must be done somehow how you want
$filename = 'test.txt';

$handle = fopen("http://www.foo.com/", "rb");
if($handle){
  $somecontent = stream_get_contents($handle);
  fclose($handle);

  $handle = fopen($filename, 'wb');
  if($handle){
    if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
    }
    echo "Success, wrote ($somecontent) to file ($filename)";
    fclose($handle);
  }else{
     echo "Cannot create file ($filename)";
     exit;
  }
}
?>

Via | Sastgroup

Pixmac
Like this post? Share It! :)
Navigation:
Related Posts:
Comments

Comments are closed.