Viewing file: functdownload.php (1.53 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php extract ($_REQUEST); function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); }
function downloadRemoteFile($tsr_fr_node,$url,$dir,$file_name = NULL){
if($file_name == NULL){ $file_name = basename($url); } $file_name_write=$file_name; $url_stuff = parse_url($url);
$port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;
$fp = fsockopen($url_stuff['host'], $port); if(!$fp){ return false;}
$query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n"; $query .= 'Host: ' . $url_stuff['host']; $query .= "\n\n"; fwrite($fp, $query); while ($tmp = fread($fp, 1024)) { $buffer .= $tmp; //echo "."; //echo $buffer.'<br>'; flush(); //ob_flush(); } preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts); $file_binary = substr($buffer, - $parts[1]); if($file_name == NULL){ $temp = explode(".",$url); $file_name = $temp[count($temp)-1]; } //$file_open = fopen($dir . "/" . date('Y-m-d_His').$file_name,'w'); //---add collegeId into filename list($filename_,$filetype_)=preg_split("/\./",$file_name_write); $filewrite=$filename_.'-'.$tsr_fr_node.'.'.$filetype_; /*$file_open = fopen($dir . "/" .$filewrite,'w'); if(!$file_open){ return false; } fwrite($file_open,$file_binary); fclose($file_open); */
if(file_exists($dir.$filewrite)) unlink($dir.$filewrite); $result = file_put_contents($dir.$filewrite, file_get_contents($url));
return true;
} ?>
|