siddscool19 Posted October 8, 2008 Share Posted October 8, 2008 I want to download file to server using curl how to do that? Can anyone help me? Link to comment https://forums.phpfreaks.com/topic/127544-download-file-to-server-using-curl/ Share on other sites More sharing options...
Orio Posted October 8, 2008 Share Posted October 8, 2008 Why not using copy() ? Do you have allow_url_fopen disabled and you can't enable it? Orio. Link to comment https://forums.phpfreaks.com/topic/127544-download-file-to-server-using-curl/#findComment-659875 Share on other sites More sharing options...
siddscool19 Posted October 8, 2008 Author Share Posted October 8, 2008 Well i want to download from a url like http://user:pass......... and i don't know about copy() if u can give an example and tell if it works with http://user:pass... And also i would like to know if its possible with curl Link to comment https://forums.phpfreaks.com/topic/127544-download-file-to-server-using-curl/#findComment-659881 Share on other sites More sharing options...
Orio Posted October 8, 2008 Share Posted October 8, 2008 Something like that? I haven't tried it, but it's supposed to work. <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.site.com/pic.jpg'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, 'username:password') $data = curl_exec(); curl_close($ch); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/127544-download-file-to-server-using-curl/#findComment-659885 Share on other sites More sharing options...
siddscool19 Posted October 9, 2008 Author Share Posted October 9, 2008 <?php /* This is usefull when you are downloading big files, as it will prevent time out of the script : */ set_time_limit(0); ini_set('display_errors',true);//Just in case we get some errors, let us know.... $filename=$_POST["filename"]; $file=$_POST["file"]; $fp = fopen (dirname(__FILE__) . '/'.$filename.'', 'w+');//This is the file where we save the information $ch = curl_init($file);//Here is the file we are downloading curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); ?> I am using this coding to download the file... It does downloads the file.. The smaller files are perfectly downloaded but the bigger files like of 100mb it does download but their link doesn't work it shows them as they doesn't exist.......... Any way to fix it? Link to comment https://forums.phpfreaks.com/topic/127544-download-file-to-server-using-curl/#findComment-660552 Share on other sites More sharing options...
Orio Posted October 9, 2008 Share Posted October 9, 2008 I believe the problem is with: curl_setopt($ch, CURLOPT_TIMEOUT, 50); You are limiting the amount of time of downloading to 50 seconds. I don't believe you can download 100MB in 50 secs. If you want it to never timeout, set it to zero (or a very big number at least). Orio Link to comment https://forums.phpfreaks.com/topic/127544-download-file-to-server-using-curl/#findComment-661190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.