Welcome Guest, Not a member yet? Register   Sign In
file_get_contents for remote files
#1

[eluser]sixpack434[/eluser]
I want to force download files on a remote server, is it possible to use file_get_contents with remote files so i can force_download e.g.

$data = file_get_contents("http://www.mysite.com/image/myphoto.jpg"); // Read the file's contents
$name = 'myphoto.jpg';

force_download($name, $data);


Thanks for your help
#2

[eluser]Pygon[/eluser]
not sure what the "force_download()" is for. The contents of the file would already be in "$data".

file_get_contents is good, but shouldn't be used for large file (anything over about 2 meg is probably going to cause problems for users with a standard 8M memory limit for PHP).

If you're going to be grabbing large files, you need to use

fopen(remote file);
fopen(local copy);
loop: fread(remote file); fwrite(local copy);
fclose(both);

Slower, but the only thing possible for larger files.
#3

[eluser]sixpack434[/eluser]
Thanks Pygon
#4

[eluser]Derek Allard[/eluser]
For the record, force_download() is part of the download helper. That said, if you've got a working solution, I wouldn't go messing too much ;D




Theme © iAndrew 2016 - Forum software by © MyBB