Download file to website using php -


this question has answer here:

i have file url !

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

and want download file , save path on website

this website ( online )

$path = "server/username/"; 

i want $url file saved $path ,,

i try

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 test code , make file download computer not website

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


Comments

Popular posts from this blog

java - Unable to make sub reports with Jasper -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -

Save and close a word document by giving a name in R -