Here is the code I use that works great. I had to write this since I
could not find anything like it for PHP.  It allows me to only include
certain extensions and auto generates a version based on number of
files to be stored as well as the total file size.  This allows you to
update files that are already stored but it will create a new version
number and force a new download of the files.  Hope it works for you!

- Peter Schmalfeldt

SAMPLE OUTPUT:  http://devmedia.taxexemptdata.com/manifest.php
SOURCE: http://www.manifestinteractive.com/usenet/manifest.phps

<code>

<?PHP
## SET CONTENT TYPE
header('Content-type: application/javascript;');
header("Cache-Control: must-revalidate");

## FUNCTION TO FETCH FILES
$subversion = 0;
function listdir($start_dir='.') {
        global $subversion;
        $desired_extension = array('js', 'css', 'png', 'gif', 'jpg', 'ico');
        $files = array();
        if(is_dir($start_dir)) {
                $fh = opendir($start_dir);
                while(($file=readdir($fh)) !== false) {
                        if(strcmp($file, '.')==0 || strcmp($file, '..')==0) 
continue;
                        $filepath = $start_dir . '/' . $file;
                        if (is_dir($filepath)) $files = array_merge($files, 
listdir
($filepath));
                        else {
                                $ext = array_reverse(explode(".", $file));
                                if(in_array($ext[0], $desired_extension)){
                                        $subversion += 
filesize($_SERVER["DOCUMENT_ROOT"].'/'.$filepath);
                                        array_push($files, $filepath);
                                }
                        }
                }
                closedir($fh);
        }
        else $files = false;
        return $files;
}

## SET LOCAL VARIABLES
$protocol = ($_SERVER['HTTPS'] == 'on') ? 'https://':'http://';
$domain = $protocol.$_SERVER['HTTP_HOST'];
$files = listdir('browser');
$total = count($files);
$current = 0;

## CREATE MANIFEST FILE
$manifest = '{'."\n";
$manifest .= '  "betaManifestVersion": 1,'."\n";
$manifest .= '  "version": "1.'.$total.'.'.$subversion.'",'."\n";
$manifest .= '  "entries": ['."\n";
foreach($files as $file){
        $current++;
        $comma = ($current == $total) ? '':',';
        $manifest .= "    { \"url\": \"{$domain}/{$file}\" }{$comma}\n";
}
$manifest .= '  ]'."\n";
$manifest .= '}'."\n";

## WRITE OUT FILE
echo $manifest;
?>

</code>

On Feb 24, 9:31 pm, meerkat <t...@tappass.com> wrote:
> Does anyone know the solution to this issue of programmatically
> creating the manifest file?
> meerkat
>
> On Jan 29, 6:29 pm, "Tosca Lahiri" <t...@toscalahiri.co.uk> wrote:
>
> > Well, when I click "capture" I get the Error 404 status code listed below.
> > This is because themanifestfile lists test.html as {"url": "test.html" ,
> > "ignoreQuery":true }. I think it should be {"url": "test/test.html" ,
> > "ignoreQuery":true }. The page, viamanifest.php, is looking for
> > -localhost/gearsTut/manifestTest/test.html. The file is really in
> > localhost/gearsTut/manifestTest/test/test.html
>
> > What do you think we should try now?TML
>
> > > -----Original Message-----
> > > From: gears-users@googlegroups.com [mailto:gears-us...@googlegroups.com]
> > > On Behalf Of carise
> > > Sent: Thursday, January 29, 2009 6:14 PM
> > > To: Gears Users
> > > Subject: [gears-users] Re:manifest.php folders
>
> > > Yes, that sure sounds like progress! How's the sample app coming
> > > along?
>
> > > On Jan 29, 6:00 am, "Tosca Lahiri" <t...@toscalahiri.co.uk> wrote:
> > > > OK. Now I get Error: Download of
> > > > 'http://localhost/gearsTut/manifestTest/test.html'failed, status code
> > > 404.
>
> > > > And if I loadmanifest.php the folder "test" is not listed and test.html
> > > is
> > > > listed as {"url": "test.html" , "ignoreQuery":
> > > > true }
>
> > > > Is this progress?
>
> > > > > -----Original Message-----
> > > > > From: gears-users@googlegroups.com [mailto:gears-
> > > us...@googlegroups.com]
> > > > > On Behalf Of carise
> > > > > Sent: Thursday, January 29, 2009 1:43 AM
> > > > > To: Gears Users
> > > > > Subject: [gears-users] Re:manifest.php folders
>
> > > > > Okay, hm, so the next thing I would do, since the test directory is in
> > > > > the same level asmanifest.php, we want to exclude it (since it's the
> > > > > directory). You can do that in the while loop which is checking the
> > > > > version/adding the files to the $files array.
>
> > > > >     if ($file<>'..' && !is_dir($file))
> > > > >       $files[]=$file;
>
> > > > > Maybe the 301 error is because Google Gears can't (not sure if that's
> > > > > true?) download/capture directories (only files), so when it tries to
> > > > > retrieve test, it complains.
>
> > > > > On Jan 28, 5:25 pm, "Tosca Lahiri" <t...@toscalahiri.co.uk> wrote:
> > > > > > OK, you have folder/file structure correct.
>
> > > > > > When I try $dirs[1] = dirname($_SERVER['SCRIPT_FILENAME']) .
> > > "/test/.";
> > > > > and
> > > > > > load go_offline.html  I get "Error: Download of
> > > > > > 'http://localhost/gearsTut/manifestTest/test'failed, status code
> > > 301".
>
> > > > > > When I directly openmanifest.php in the browser (FF) I see an entry
> > > for
> > > > > the
> > > > > > folder "test" (which I don't want) and an entry for test.html.
>
> > > > > > {
> > > > > >   "betaManifestVersion": 1,
> > > > > >   "version": "1233191231",
> > > > > >   "entries": [
> > > > > >     {"url": "." , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "articleadd.php" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "articleform.html" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "articles.php" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "Copy ofmanifest.php" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "db_params.php" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "gears_init.js" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "go_offline.html" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "go_offline2.js" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "manifest.php" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "oldgo_offline.js" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "test" , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "." , "ignoreQuery":
> > > > > > true },
> > > > > >     {"url": "test.html" , "ignoreQuery":
> > > > > > true },
> > > > > >  {"url": "manifest.php" , "ignoreQuery": true }
> > > > > >   ]
>
> > > > > > }
>
> > > > > > As far as I understand I need themanifestto say {"url":
> > > > > "test/test.html" ,
> > > > > > "ignoreQuery":true }.
>
> > > > > > So, problems:
> > > > > > 1. FF or IE not downloading "test" folder and its contents (302 or
> > > 301
> > > > > > status codes)
> > > > > > 2.manifest.php directly in browser not correctly listing
> > > test/test.html
> > > > > > 3. Not all files in home directory listed when loadingmanifest.php
> > > in
> > > > > > browser.
>
> > > > > > That is a summary of what is and is not happening.
> > > > > > What are the next steps do you think?
> > > > > >TML
>
> > > > > > > -----Original Message-----
> > > > > > > From: gears-users@googlegroups.com [mailto:gears-
> > > > > us...@googlegroups.com]
> > > > > > > On Behalf Of carise
> > > > > > > Sent: Thursday, January 29, 2009 12:52 AM
> > > > > > > To: Gears Users
> > > > > > > Subject: [gears-users] Re:manifest.php folders
>
> > > > > > > Hmm... ok, I think I understand the situation though I'm not sure
> > > why
> > > > > > > the code is not working... So you have a directory under the path,
> > > > > > > $_SERVER['SCRIPT_FILENAME'], and the directory is called "test"?
>
> > > > > > > Here's another shot in the dark... do you get the same results
> > > using:
>
> > > > > > > $dirs[1] = dirname($_SERVER['SCRIPT_FILENAME']) . "/test/.";
>
> > > > > > > (assumingmanifest.php and the test/ directory are in the same
> > > level)?
>
> > > > > > > On Jan 28, 4:32 pm,TML<t...@toscalahiri.co.uk> wrote:
> > > > > > > > Also, dir[0] is not returning ALL  the files in the home
> > > directory.
> > > > > > > > The files being returned are those listed above. It is returning
> > > > > some
> > > > > > > > of the php files, some of the html files and some of the js
> > > > > > > > files...can't see a logical pattern of those being not listed.
>
> > > > > > > > In Firefox getthing Status Code 301 now.
> > > > > > > >TML
>
> > > > > > > > On Jan 29, 12:12 am,TML<t...@toscalahiri.co.uk> wrote:
>
> > > > > > > > > HI carise (and others)
>
> > > > > > > > > I have changed from Firefox to IE. Now in the space where I
> > > get
> > > > > the
> > > > > > > > > status messages when clicking "Capture" and invoke the
> > > > >manifest.php I
> > > > > > > > > get:
>
> > > > > > > > > Status Message: Error: Download of 'http://localhost/gearsTut/
> > > > > > > > > manifestTest/test' failed, status code 302.
> > > > > > > > >  Looked this up on Google and it means "Found" and is to do
> > > with
> > > > > > > > > redirection I think. Not sure of its implications here.
>
> > > > > > > > >TML
>
> > > > > > > > > On Jan 28, 11:57 pm, "Tosca Lahiri" <t...@toscalahiri.co.uk>
> > > > wrote:
>
> > > > > > > > > > Hi,
>
> > > > > > > > > > I have files in "C:/Program Files/Apache Software
> > > > > > > > > > Foundation/Apache2.2/htdocs/gearsTut/manifestTest - these
> > > are
> > > > > being
> > > > > > > reported
> > > > > > > > > > by openingmanifest.php in browser. And one file (test.htm)
> > > > > > > C:/Program
> > > > > > > > > > Files/Apache Software
> > > > > > > Foundation/Apache2.2/htdocs/gearsTut/manifestTest/test
> > > > > > > > > > . It is test/test.htm that is not being reported.
>
> > > > > > > > > > Using $dirs[1] = "C:/Program Files/Apache Software
> > > > > > > > > > Foundation/Apache2.2/htdocs/gearsTut/manifestTest/test/.";
> > > the
> > > > > > > output is:
> > > > > > > > > > {
> > > > > > > > > >   "betaManifestVersion": 1,
> > > > > > > > > >   "version": "1233157431",
> > > > > > > > > >   "entries": [
> > > > > > > > > >     {"url": "." , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "articleadd.php" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "articleform.html" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "articles.php" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "db_params.php" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "gears_init.js" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "go_offline.html" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "go_offline2.js" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "manifest.php" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >     {"url": "oldgo_offline.js" , "ignoreQuery":
> > > > > > > > > > true },
> > > > > > > > > >  {"url": "manifest.php" , "ignoreQuery": true }
> > > > > > > > > >   ]
>
> > > > > > > > > > }
>
> > > > > > > > > > What do you think?
>
> > > > > > > > > >TML
>
> > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > From: gears-users@googlegroups.com [mailto:gears-
> > > > > > > us...@googlegroups.com]
> > > > > > > > > > > On Behalf Of carise
> > > > > > > > > > > Sent: Wednesday, January 28, 2009 11:32 PM
> > > > > > > > > > > To: Gears Users
> > > > > > > > > > > Subject: [gears-users] Re:manifest.php folders
>
> > > > > > > > > > > Ok.. So let me ask.
>
> > > > > > > > > > > 1) Is        "C:/Program Files/Apache Software
> > > > > > > Foundation/Apache2.2/
> > > > > > > > > > > htdocs/gearsTut/manifestTest/test"   the directory that
> > > you
> > > > > want
> > > > > > > to
> > > > > > > > > > > get files from?
>
> > > > > > > > > > > If yes, then change the directory name to:
>
> > > > > > > > > > > "C:/Program Files/Apache Software
> > > > > > > Foundation/Apache2.2/htdocs/gearsTut/
> > > > > > > > > > > manifestTest/test/."       <-- notice the /. after "test".
>
> > > > > > > > > > >http://us3.php.net/manual/en/function.dirname.php(php.net's
> > > docs
> > > > > page
> > > > > > > > > > > on using dirname())
>
> > > > > > > > > > > 2) If the above doesn't work, what kind of output are you
> > > > > getting
> > > > > > > from
> > > > > > > > > > > using the above?
>
> > > > > > > > > > > On Jan 28, 3:29 pm, "Tosca Lahiri"
>
> ...
>
> read more »

Reply via email to