Implementing download progress

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi again:

I have successfully implemented a class that uses the
code examples and suggestions from the good folks
on this list.

I have a few lingering issues:

1: When the code runs successfully, I do not get a detectable return value.
    the code sets $_out['success'] = true;
this should be passed out via the call to run() but the code that watches the return value does not seem to see anything (evidenced by no report, where as a return value of $_out[error] is detected and displayed in the display page.
 Q Why would this be?

2: To make this a bit more independent I have tried to use the following test
   if( strpos( self::$_input['targ'], getcwd()) < 0)
     {
     /*
0 can be a valid strpos integer. So doing !strpos() will also fail because it should be detected as starting at 0. I know the negative return value may or may not
      be FALSE according the my copy of the manual.
    */
      $_file = getcwd().self::$_input['targ'];
    }
meaning if the full path is not already present in the input value , the code should add it. If the file will not resolve with the full path added, it won't be a valid path/file; to add some
sanity checking.
But it is not seeing the situation as I have coded it: the input file has path info relative to the cwd. So the full path value should not be detected and the cwd part should be added

3: Now to expand to being able to download directories with files and sub directories.
  ( as for example downloading the php manual as chunked html )

Here is the full class def:

class _DOWNLOADER
     {
      private static $_class = '';
      private static $_input = array();
      public function __construct($_input) // $_input arg is $_POST;
             {
              self::$_class = get_class($this);
              self::$_input = $_input;
             }

      public function run()
             {
              return self::downLoad();
             }

      private function downLoad()
             {
              $_out = array();
              $_file = '';
              $_cd = getcwd();
              $_file = $_cd.self::$_input['targ'];
              if(!is_file($_file))
                {
$_out['error'] = self::$_class."->".__FUNCTION__." error: ".$_file." not found"; //self::$_input['targ']
                 return $_out;
                }
              $_file = basename($_file);
              $_fSize = filesize($_file);
              header('Content-Description: File Transfer');
              header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.'"'. $_file.'"');
              header('Content-Transfer-Encoding: binary');
              header('Connection: Keep-Alive');
              header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
              header('Pragma: public');
              header('Content-Length: ' . $_fSize);
              ob_clean();
              flush();
              readFile($_file);
              $_out['success'] = true;
              return $_out;
             }
     }

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux