note 32816 modified in function.file-put-contents by pollita
| From: | pollita@php.net | Date: | Mon, 23 Jun 2003 21:21:08 +0000 |
| Subject: | note 32816 modified in function.file-put-contents by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50903@lists.php.net to get a copy of this message | ||
[ Editor's Note: The following can also be done using copy(). i.e.: copy('http://www.example.com/foo/bar.txt','bar.txt');
]
Here is a simple example to fetch a remote file and write it to a local file. Note: you need to have
write permissions to the directory you are writing the file to.
<?php
// just so we know it is broken
error_reporting(E_ALL);
// specify a file, in this cast the php logo
$url='http://static.php.net/www.php.net/images/php.gif';
// specify our local filename
$filename='phplogo.gif';
// snarf the remote file
$remote_file=file_get_contents($url);
// write the new file
if(!@file_put_contents($filename, $remote_file)){
echo "Unable to write to file $filename";
}else{
echo "Success writing to $filename";
}
?>
--was--
Here is a simple example to fetch a remote file and write it to a local file. Note: you need to have
write permissions to the directory you are writing the file to.
<?php
// just so we know it is broken
error_reporting(E_ALL);
// specify a file, in this cast the php logo
$url='http://static.php.net/www.php.net/images/php.gif';
// specify our local filename
$filename='phplogo.gif';
// snarf the remote file
$remote_file=file_get_contents($url);
// write the new file
if(!@file_put_contents($filename, $remote_file)){
echo "Unable to write to file $filename";
}else{
echo "Success writing to $filename";
}
?>
http://www.php.net/manual/en/function.file-put-contents.php