php – Can i use this statement? – Education Career Blog

$file = 'example.txt';
$newfile = 'example.txt.bak';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";

Now instead of example.txt can i use "" ?

Is it possible ?


Yes you can, as long as allow_url_fopen is enabled in your PHP config.


Yes, it is possible. As the manual says:

Both source and dest may now be URLs if the “fopen wrappers” have been enabled. See fopen() for more details.


You can read remote files using PHP

$contents = '';
$file = fopen ("", "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
while (!feof ($file)) {
    $line = fgets ($file, 1024);
    $contents .= $line;

echo $contents;



As Emil Vikström said you must have allow_url_fopen directive enabled. Documentation also says that this directive can be set only into php.ini file.

Leave a Comment