3

I have this code and it works but has a limitation only can copy files of 4.0mb, someone can help me to increase that size to copy files larger. thanks

<? $archivo_origen=$_POST["origen"]; $archivo_destino=$_POST["destino"]; function descarga_archivo ($archivo_origen,$archivo_destino){ $mi_curl = curl_init ($archivo_origen); $fs_archivo = fopen ($archivo_destino, "w"); curl_setopt ($mi_curl, CURLOPT_FILE, $fs_archivo); curl_setopt ($mi_curl, CURLOPT_HEADER, 0); curl_exec ($mi_curl); curl_close ($mi_curl); fclose ($fs_archivo); } descarga_archivo($archivo_origen,$archivo_destino); header("location: index.php"); ?> 
3
  • Instead of using CURL, you might try file_get_contents($url)? Commented Aug 11, 2012 at 5:05
  • This seems to be a solution: stackoverflow.com/questions/6409462/… Commented Aug 11, 2012 at 5:11
  • the problem is that this code runs on a free hosting server and I not have all the features enabled, so I use cURL, however would appreciate an example of file_get_contents ($ url) to prove it. Commented Aug 11, 2012 at 5:12

1 Answer 1

0
$fs_origen = fopen($archivo_origen, 'r'); $fs_destino = fopen($archivo_destino, 'w'); while($data = fread($fs_origen, 4096)) fwrite($fs_destino, $data); fclose($fs_origen); fclose($fs_destino); 

EDIT: replace stream_copy_to_stream with loop.

Sign up to request clarification or add additional context in comments.

5 Comments

with all the codes that I can use just copy 4.0mb, I do not know if it will be by the server configuration
It sounds like both curl and stream_copy_to_stream run into php memory size limits. You may have to write your own loop using fread() and fwrite() in smaller chunks.
if you could give me an example, I do not know much about php. Use this code to download files that are denied because I am from Cuba and my proxy does not allow downloading files *. exe, *. zip Thanks
thanks for the help but I think due to some configuration of my hosting, only copy 4.0mb. Thanks for your time
Sounds like the hosting server has a file size limit. They probably don't want you filling up their disk with junk, or using it to host lots of illegal downloads.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.