Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   PHP, PERL, MySQL, JavaScript (https://forum.antichat.xyz/forumdisplay.php?f=37)
-   -   Загрузка ПХП (https://forum.antichat.xyz/showthread.php?t=73230)

lomerok 09.06.2008 22:40

Загрузка ПХП
 
нужен скрипт скачки файла на комп...
пробую так :
PHP код:

<? 
  $downloadfile
=$_GET['downloadfile'];
if(isset(
$downloadfile))

  
 if(isset(
$_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) 
   
Header('Content-Type: application/force-download'); 
 else 
   
Header('Content-Type: application/octet-stream'); 
  
 
Header('Accept-Ranges: bytes'); 
 
//Header('Content-Length: '.filesize($downloadfile)); 
 
Header('Content-disposition: attachment; filename="'.$downloadfile.'"'); 
$downloadfile getcwd()."\\$downloadfile";
echo 
file_get_contents("$downloadfile");  
  exit();


 
?>

нефурычит

d_x 09.06.2008 23:18

Вот функция, которая ещё и докачку поддерживает.
PHP код:

function downloadFile($filename$mimetype='application/octet-stream')
{
  
$from=$to=0;
  
$cr=NULL;
  if(isset(
$_SERVER['HTTP_RANGE']))
  {
    
$range=substr($_SERVER['HTTP_RANGE'],strpos($_SERVER['HTTP_RANGE'],'=')+1);
    
$from=strtok($range,'-');
    
$to=strtok('/');
    if(
$to>0$to++;
    if(
$to$to-=$from;
    
header('HTTP/1.1 206 Partial Content');    
    
$cr='Content-Range: bytes'.$from.'-'.(($to)?($to.'/'.$to+1):filesize($filename));
  }
  else
    
header('HTTP/1.1 200 Ok');

  
$etag=md5($filename);
  
$etag=substr($etag08).'-'.substr($etag87).'-'.substr($etag158);
  
header('ETag: "'.$etag.'"');
  
header('Accept-Ranges: bytes');
  
header('Content-Length: '.(filesize($filename)-$to+$from));
  if(
$crheader($cr);    header('Connection: close');
  
header('Content-Type: '.$mimetype);
  
header('Last-Modified: '.gmdate('r',filemtime($filename))); $f=fopen($filename'r');
  
header('Content-Disposition: attachment; filename="' basename($filename) . '";');
  if(
$from)fseek($f,$from,SEEK_SET);
  if(!isset(
$to) or empty($to))
  {
    
$size=filesize($filename)-$from;
  }
  else
  {
    
$size=$to;
  }

  
$downloaded=0;

  while(!
feof($f) and !connection_status() and ($downloaded<$size))
  {
    echo 
fread($f,512000);
    
$downloaded+=512000;
    
flush();
  }

  
fclose($f);



lomerok 09.06.2008 23:30

спсибо разобрался уже ....


Время: 10:01