30 May 2011 @ 12:58 PM 

I have a software app that checks for updates and downloads them from http://www.some_random_website.com/updatefile.rar

However, I’ve noticed that ISPS tend to cache these files so the software app isnt always getting the latest file.

step 1 – create a php function to download a file

<?php
 
$filename = $_GET['filename'];
$path = $_SERVER['DOCUMENT_ROOT'] . "/$filename";
if ($fd = fopen($path, "r")) 
{
    $fsize = filesize($path);
    header("Cache-Control: no-cache, must-revalidate"); 
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); 
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"" . $filename . "\"");
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while (!feof($fd)) 
    {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose($fd);
?>

step 2 – rewrite urls so that when requesting /some_file.rar, it redirects to the php app as defined

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.rar$ ./getfile.php?filename=$1.rar [NC]
Posted By: Zayin
Last Edit: 30 May 2011 @ 12:58 PM

EmailPermalink
Tags
Categories: php


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 38
  • Comments » 57
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Links



    No Child Pages.

Portfolio



    No Child Pages.