We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7923
    • 4,213 Posts
    Quote from: Boby at Sep 08, 2006, 05:59 PM

    kylej, would be nice if you can add the filesize header in a future version.
    Good idea, but I suggest that it would be done as a configurable option, because when not givin the filesize in header it prevents people using download managers that flood the servers..



      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
      • 1273
      • 11 Posts
      I could not download big files (>700 MB). I’m using Abyss Web Server, not apache. My site is running on my local server and when I try to download big file browser starts loading the page but there is no dialog for saving file. On the server apears a proccess php-cgi.exe (this file is used to proccess php scripts inn FastCGI mode) which uses a lot of memory (>200 MB).

      It looks like the file is going as part of a php script. A assumed that the script like FileDownload should just get the query and output a generated link for the file and it does not need 200 MB for that operation.

      How could I fix that? Is the problem in Abyss Web Server? Or php is misconfigured? Or the problem is in FileDownload? Does anybody tried to download big files?

        • 36541
        • 222 Posts
        Useful snippet, thanks for sharing smiley However, I do have some bug reports/feature requests:

        1. Filenames with non-ASCII characters do not display properly and are can not be downloaded (en error occurs). Seems like endcoding of filenames should be used.

        2. I second Boby’s suggestion of adding a file size to the HTTP header. It could be a parameter in the snippet call (in case someone would want not to provide the file size).

        3. I would handle file icons in a different way: by CSS backgrounds. Supplying a background is semantically more correct that using images (<img> elements) which have only presentational purpose. Anyway it would suffice to provide a class placeholder which would return the file type. For example for .jpg images it would return
         class="jpg"
        and so on.

        4. File size is displayed with incorrect (non-standard) abbreviations. For bytes it should be ’B’, for kilobytes - KB’, and for megabytes - ’MB’, and for gigabytes - ’GB’. See byte in Wiki.

        Notice: Because the binary meaning differs from the physical defined with SI prefixes it is advised to use their uppercase variation. Thus instead of the SI kB for kilobytes one should use KB.

        5. The splitter string could also be a parameter. The ’
        ’ you used is not compliant with XHTML (it should be ’
        ’) and although it is stripped from the template it should be semantically correct. Personally I prefer to put splitters in the HTML comment, eg. ’<!-- split -->’.

        #1-2 are urgent, #3 is important, #4-5 can be easily modified without messing to much with the snippet code and thus have a lower priority.

        Also, pay attention that files’ extensions can have more than 3 characters.

        Thanks.
          This is the web: the only thing you know about who will come is that you don't know who will come.
          • 15987
          • 786 Posts
          I have release FileDownload v2.0, get it here: http://modxcms.com/FileDownload-2.0-1097.html


          • Completly rewritten with ’OOP’ goodness.
          • Ability to specify multiple folders for display in one snippet call.
          • Expanded template support, now with templates for folders and files.
          • Ability to store download counts in databse or file.
          • Parameters to add custom classes to the templates (including extension class).
          • Extra placeholders available for more output options.
          • Image - Extension associations now stored in a chunk so you can set different images per snippet call.
          • Ability to use the download script without download counting.
          • The file size can be passed to the download script to display download progress.
          • And many other changes...

          Also check my site here for info and examples:
          http://www.muddydogpaws.com/notebook/filedownload-rewrite.html
            • 36541
            • 222 Posts
            Great to see you listened to our suggestions! Thanks smiley

            Attention: you have left PHP tags in ’FileDownload2.0.php’!

            What has left unimplemented from my original post:

            Quote from: grad at Sep 26, 2006, 03:15 AM

            1. Filenames with non-ASCII characters do not display properly and are can not be downloaded (en error occurs). Seems like endcoding of filenames should be used.

            It is a real problem with languages using non-ASCII characters. The files should be served with descriptive names and I can’t require editors to change the file names to ASCII-compatible.

            I was playing a little with your code and thought of a possible solution. The problem with non-ASCII characters in filenames is not in reading them by script but in serving them to the browser. Resolving this would require to provide a name the file it should be listed and served with which would replace the filename read by the script. In short - the script should serve the ’title’ of the file (of course only when it has been provided) instead of its real filename. I modified a piece of your code and came to a working prototype:

            <?php
            $folder = '/files';
            $folder = trim($folder," \t\\/");
            
            $file = 'file.ext'; // the real file name as in the filesystem
            $fileTitle = 'The file title.ext'; // the 'title' of the file
            
            /* End parameters. Do not change the code below!
            ----------------------------------------------- */
            
            # Send the user their download
            $fp = fopen($file,"r");
            $filedata=fread($fp,filesize($file));
            fclose($fp);
            
            header('Pragma: private');
            header('Cache-control: private, must-revalidate');
            header('Content-type: ' . mime_content_type($file)); // check it!
            header ('Content-Length: ' . filesize($file));
            if (preg_match('#MSIE ([0-9].[0-9]{1,2})#', getenv('HTTP_USER_AGENT')))
            {
            	header('Content-Disposition: attachment; filename="' . rawurlencode($fileTitle) . '"');
            }
            else // Opera, Gecko family and others
            {
            	header('Content-Disposition: attachment; filename="' . $fileTitle . '"');
            }
            
            print($filedata);
            ?>


            Because the snippet uses the filesystem it assumes that files will be added through it, ie. FTP, network share or similar. Following that logic it would be the most natural for the user to provide the ’titles’ (if needed) also by that way, that is in a file specific for a given folder. I thought of using a single text file with uniform name that would serve as a library that contains:

            - filename,

            - a file exclusion marker (ie. by default all files of specified type should be listed, but if the user wants to exclude a specific file he should mark it with, say, ’0’; this should also allow to include a file which is excluded by the filter by marking it with ’1’),

            - a title for the file (if empty, then the filename should be used),

            - a description for the file

            - a count download marker (ie. to count it or not with logic analogous to the inclusion marker)

            - a count number (updated by the snippet).

            All fields (except filename) could be empty. A record of the library file might look like (assuming double pipe as a field separator):

            file.txt||1||title to display and serve on downloading.txt||A description.||1||1234


            Keeping the library file within the filesystem has an advantage of using any way of generating it and resolves a problem of access permissions. Keeping it in the is not so flexible.

            It is up to you to decide if you wish to use my idea or not. I think it would add to usability.

            Quote from: grad
            4. File size is displayed with incorrect (non-standard) abbreviations. For bytes it should be ’B’, for kilobytes - KB’, and for megabytes - ’MB’, and for gigabytes - ’GB’. See byte in Wiki.

            Notice: Because the binary meaning differs from the physical defined with SI prefixes it is advised to use their uppercase variation. Thus instead of the SI kB for kilobytes one should use KB.

            This one is not a big issue. However it would be nice to use standardized abbreviations.
              This is the web: the only thing you know about who will come is that you don't know who will come.
              • 15987
              • 786 Posts
              This one is not a big issue. However it would be nice to use standardized abbreviations.

              I did change the abbreviations to use what is in the wikipedia.

              I will give the non-Ascii character problem a look, sorry I missed that one. Sounds like some good ideas on how to fix it though.

              Attention: you have left PHP tags in ’FileDownload2.0.php’!

              Oops, I will get those removed, although in 0.9.5 it does not matter if they are included.
                • 36541
                • 222 Posts
                Quote from: kylej at Oct 20, 2006, 10:05 AM

                I did change the abbreviations to use what is in the wikipedia.

                Sorry for not being explicit. There are still ’bytes’ in the filedownload.class.inc.php.

                I will give the non-Ascii character problem a look, sorry I missed that one. Sounds like some good ideas on how to fix it though.

                Nice to hear that smiley

                Attention: you have left PHP tags in ’FileDownload2.0.php’!

                Oops, I will get those removed, although in 0.9.5 it does not matter if they are included.

                I noticed it today. However in pre-0.9.5 it does matter wink
                  This is the web: the only thing you know about who will come is that you don't know who will come.
                  • 6726
                  • 7,075 Posts
                  Great work on version 2.0 !
                  And very nice documentation grin

                  Hats off for this one !
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 7923
                    • 4,213 Posts
                    Yes, Very nice work! And very very good documentation and examples etc. You rock! grin


                      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                      • 6726
                      • 7,075 Posts
                      I’ve recently upgraded to 2.0 (previously happy user of 1.7) and got this problem :

                      PHP error debug
                        Error: 	filename: data.db.class.inc.php, exec_fname: /home/gican/www/assets/snippets/filedownload/filedownload.class.inc.php, filepath: /home/gican/www/assets/snippets/filedownload/data.db.class.inc.php	 
                        Error type/ Nr.: 	Warning - 2	 
                        File: 	/home/gican/www/assets/snippets/filedownload/filedownload.class.inc.php	 
                        Line: 	8	 
                        Line 8 source: 	include_once "data.db.class.inc.php";


                      My config is PHP 5.1.6, MySQL 5.0.22a, Apache 1.3.34
                      And oh, I am using MODx 0.9.5 rev1785 (so used to run 0.9.5 almost forgot to mention it tongue)

                      Any idea ?
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l&#39;outil id