A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearBest way to download a file in PHP - page 1
User InfoPosts
Best way to download a file in PHP#1
Which would be the best way to download a file from another domain in PHP?
i.e. A zip file.

posted date: 2009-04-07 19:47:00

Re: Best way to download a file in PHP#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-07 19:47:01

Re: Best way to download a file in PHP#3
The easiest one is file_get_contents(), a more advanced way would be with cURL for example. You can store the data to your harddrive with file_put_contents().

posted date: 2009-04-07 19:49:00

Re: Best way to download a file in PHP#4
gotta be careful with file_get_contents() though. All of that data is held in a string. PHP's default memory limit is usually fairly low (16M IIRC), so if he's on shared hosting and the said files he's downloading are fairly large... he's gonna have a hard time with that.

posted date: 2009-04-07 19:55:00

Re: Best way to download a file in PHP#5
unless you have a nice shared host and he will bump the memory for you on PHP, or you have your own server. Even then it's still kind of an iffy idea.

posted date: 2009-04-07 19:56:00

Re: Best way to download a file in PHP#6
Also, file_get_contents is disabled on more secure boxes to avoid hacker attempts when trying to access files on other domains.

posted date: 2009-04-07 21:30:00

Re: Best way to download a file in PHP#7
normally, the fopen functions work for remote files too, so you could do the following to circumvent the memory limit (but it(s slower than file_get_contents)<?php$handle = fopen("http://www.example.com/", "rb");$fp = fopen($localfile, (w();$contents = ((;while (!feof($handle)) { $content = fread($handle, 8192); fwrite($fp, $content);}fclose($handle);fclose($fp);?>copied from here: http://www.php.net/fread

posted date: 2009-04-08 05:33:00

Re: Best way to download a file in PHP#8
This one is not so bad.. solved my problem...

posted date: 2011-03-19 10:40:00

Re: Best way to download a file in PHP#9
=> Use file_get_contents() for small files and cURL for bigger downloads.

posted date: 2011-11-23 05:57:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.