Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Force file download

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Force file download

Postby cyrus » Wed Nov 13, 2002 8:28 am

Ok. I have some code:
Code: Select all
<?
  global $HTTP_USER_AGENT;
  $path = "video.wingit.boadway.ca/rubik.mov";
  $file=basename($path);
  $size = filesize($size);
  header("Content-Type: application/octet-stream");
  header("Content-Type: application/force-download");
  header("Content-Length: $size");
  // IE5.5 just downloads index.php if we don't do this
  if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {
    header("Content-Disposition: filename=$file");
    } else {
      header("Content-Disposition: attachment;filename=$file");
      }
  header("Content-Transfer-Encoding: binary");
  $fh = fopen($path, "r");
  fpassthru($fh);
?>


My problem is that it won't download remote files! They have to be local. So:
HOW DO I FORCE DOWNLOAD A REMOTE FILE?

Thanks
cyrus
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Nov 13, 2002 8:21 am
Location: under a rock canada

Postby Oleg Butuzov » Sun Nov 24, 2002 3:47 am

http://php.spb.ru

Code: Select all
<?
     
     $so = fsockopen("php.spb.ru", 80, &$errno, &$errstr, 30);
     fputs($so,"GET /files/notepad.exe HTTP/1.0\nHOST: php.spb.ru\n\n");

     while(fgets($so,2048)!="\r\n" && !feof($so));
   
     unset($buf);
     while(!feof($so)) $buf.=fread($so,2048);
 
      fclose($so);
      echo "Download fine, size ".strlen($buf)." bytes."; flush();

     $f=fopen("download.tmp","wb+");
     fwrite($f,$buf,strlen($buf));
     fclose($f);
   
?>
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron