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 - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -