So i've implemented a snippet from one of my functions in the uploaderurl.php file to add cURL support while URL uploading. For my own use i removed the whole download function in uploaderurl.php and replace to only use cURL. However cURL support could also be implemented so that if the original(fopen) method fails then use cURL. cURL has proven to be more efficient and faster so it could be set as the default method.
Below are the different versions of the download function located at the bottom of the uploaderurl.php file (line 671):
For "If URL fopen fails use cURL":
function download ($file_source, $file_target)
{
// Preparations
$file_source = str_replace(' ', '%20', html_entity_decode($file_source)); // fix url format
if (file_exists($file_target)) { chmod($file_target, 0777); } // add write permission
// Begin transfer
if (($rh = fopen($file_source, 'rb')) === FALSE) {
// fopen Failed Using cURL instead
$fp = fopen ($file_target, 'w+');
$ch = curl_init($file_source);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
$good = curl_exec($ch);
curl_close($ch);
fclose($fp);
if($good == true){
return true;
}else{
return false; // cURL download Failed
}
}
if (($wh = fopen($file_target, 'wb')) === FALSE) { return false; } // error messages.
while (!feof($rh)){
// unable to write to file, possibly because the harddrive has filled up
if (fwrite($wh, fread($rh, 1024)) === FALSE) { fclose($rh); fclose($wh); return false; }
}
// Finished without errors
fclose($rh);
fclose($wh);
return true;
}
For " if cURL fails use URL fopen":
function download ($file_source, $file_target)
{
// Preparations
$file_source = str_replace(' ', '%20', html_entity_decode($file_source)); // fix url format
if (file_exists($file_target)) { chmod($file_target, 0777); } // add write permission
// Begin transfer
// Using cURL
$fp = fopen ($file_target, 'w+');
$ch = curl_init($file_source);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
$good = curl_exec($ch);
curl_close($ch);
fclose($fp);
if($good == true){
return true;
}else{
//Use URL fopen
if (($rh = fopen($file_source, 'rb')) === FALSE) { return false; } // fopen handles
if (($wh = fopen($file_target, 'wb')) === FALSE) { return false; } // error messages.
while (!feof($rh)){
// unable to write to file, possibly because the harddrive has filled up
if (fwrite($wh, fread($rh, 1024)) === FALSE) { fclose($rh); fclose($wh); return false; }
}
// Finished without errors
fclose($rh);
fclose($wh);
return true;
}
}

Sign In
Register
Help

MultiQuote