1

I have a file with URL !

$url = "http://www.example.com/aa.txt";

and I want to download this file and save it to path on my website

this is my website ( online )

$path = "server/username/";

i want the $url file saved to $path ,,

i try this

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}
?>

when I test the code , it make the file download to my computer not to my website

bartektartanus
  • 15,284
  • 6
  • 74
  • 102

1 Answers1

1

you can use file_put_contents();

see manual here:http://php.net/manual/en/function.file-put-contents.php

a different implementation here:http://www.finalwebsites.com/forums/topic/php-file-download

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44