codingtcher.com
Theme Night
Home
Login

Php file upload from url

Home » Tutorial Post » Php file upload from url
function Saveurlfile($geturl,$savefile){
                $ch = curl_init(trim($geturl));
				curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
				curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)');
				curl_setopt($ch, CURLOPT_AUTOREFERER, true);
				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);	// required to follow redirected urls
				curl_setopt($ch, CURLOPT_MAXREDIRS, 4);	// set max redirect limit
				curl_setopt($ch, CURLOPT_FAILONERROR, 1); // dont hang
				$outfile = fopen($savefile, 'wb');
				curl_setopt($ch, CURLOPT_FILE, $outfile);
				$c = curl_exec($ch);
				curl_close($ch);
}

Saveurlfile('anyfileurl',$_SERVER['DOCUMENT_ROOT']);

Related Post