Re: Download code for downloading a file

2009-07-27 Thread delocalizer

Just so this is searchable  on the record here at the cakephp group:
using ob_gzhandler in conjunction with ob_* functions like the
ob_clean and ob_end_clean in the code snippets in above posts can
cause headaches.
In particular, you might have output_handler set = ob_gzhandler in
your php.ini and not even realise it... this caused downloads to fail
completely for me (php-5.1.6 on CentOS 5.3). Seems to be an old php
bug (http://bugs.php.net/bug.php?id=34071  variations...).
Answer = if you want to use ob_gzhandler, invoke it at function level,
and not in conjunction with ob_clean.

On Jul 24, 6:34 pm, Vijay Kumbhar k.vidn...@gmail.com wrote:
 Hey Crazy,

 thanks a lot ... i will try this out.



 On Fri, Jul 24, 2009 at 1:56 PM, Crazy crazy...@gmail.com wrote:

  Will there be allot of file downloads?

  If there will be a big load on the site from file downloads,
  especially big files. Then it's not smart to handle it in cakephp.
  Especially if you want to support download accellerators/resume
  support

  On every request(someone that uses a download accelerator and makes 10
  requests), the cakephp framework is loaded.
  This is accually not needed, because it's a plain file download.
  Even if you want to check a couple of things in the database, it's
  better to do it manually.

  This ofcouse depends on the situation you're in.
  In my case, using cakephp this way would crash my server within 5
  minutes(if not faster)

  You can find the code I use here:

 http://pastebin.com/f179e1e49

  I've been using it for several years and transfer 15 to 20tb per month
  using that piece of code.

  /Crazy

  On Jul 24, 9:58 am, Vijay Kumbhar k.vidn...@gmail.com wrote:
   Yeah...

   Thanks rufus it works .

   only i changed this line,

   header('Content-Type: application/octet-stream'); to

   header(Content-Type: .$result['Application']['resume']).);

   that is the content type of the uploaded file coming from my database.

   Thanks again...

   On Fri, Jul 24, 2009 at 12:53 PM, Rufus rufusp...@gmail.com wrote:

Here is my code:

pdfDir is defined constant fyi

       function download($id = null) {

               if (!$id  empty($this-data)) {
                       $this-Session-setFlash(__('Invalid Invoice',
true));
                       $this-redirect(array('action'='index'));
               }

               Configure::write('debug', 0);
               $file = $this-Invoice-findById($id);
   if (file_exists(pdfDir.$file['Invoice']['file_name'])) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/octet-stream');
       header('Content-Disposition: attachment; filename='.basename
(pdfDir.$file['Invoice']['file_name']));
       header('Content-Transfer-Encoding: binary');
       header('Expires: 0');
       header('Cache-Control: must-revalidate, post-check=0, pre-
check=0');
       header('Pragma: public');
       header('Content-Length: ' . filesize(pdfDir.$file['Invoice']
['file_name']));
       ob_clean();
       flush();
       readfile(pdfDir.$file['Invoice']['file_name']);
       exit;
   } else {
                       $this-Session-setFlash(__('File Does Not
  Exist',
true));
                       $this-redirect(array('action'='index'));
    }

       }

On Jul 24, 12:44 am, Vijay k.vidn...@gmail.com wrote:
 Hello All,

 I uploads the files to webroot/uploads folder from the file uploading
 component.

 Now I am trying to download that file from webroot/uploads folder but
 it is giving me 0 byte file.

 Code is as follows,

 function admin_download($id)
     {
         $this-adminchecksession();
             // you'll want to check the login status here ...

             $result = $this-Application-findById($id);

             Configure::write('debug', 0);
             $this-view = 'Media';

             /* MediaView is really irritating
              */
             //$name = $result['Application']['resume'];

             $ext = explode(. ,$result['Application']['resume']);

             $params = array(
                     'name' = $ext[0],
                     'download' = true,
                     'extension' = $ext[1],
                     'path' = APP.webroot/uploads.DS,
                     'mimeType' = array($result['Application']
 ['type'])
             );

             $this-set($params);

     }

 Please help me on this.

   --
   Thanks  Regards,
   Vijayk.
   Co-founder (www.weboniselab.com)

   You Bring the Dreams, We'll Bring the Means

 --
 Thanks  Regards,
 Vijayk.
 Co-founder (www.weboniselab.com)

 You Bring the Dreams, We'll Bring the Means
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the 

Re: Download code for downloading a file

2009-07-24 Thread Rufus

Here is my code:

pdfDir is defined constant fyi


function download($id = null) {

if (!$id  empty($this-data)) {
$this-Session-setFlash(__('Invalid Invoice', true));
$this-redirect(array('action'='index'));
}

Configure::write('debug', 0);
$file = $this-Invoice-findById($id);
if (file_exists(pdfDir.$file['Invoice']['file_name'])) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename
(pdfDir.$file['Invoice']['file_name']));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-
check=0');
header('Pragma: public');
header('Content-Length: ' . filesize(pdfDir.$file['Invoice']
['file_name']));
ob_clean();
flush();
readfile(pdfDir.$file['Invoice']['file_name']);
exit;
} else {
$this-Session-setFlash(__('File Does Not Exist', 
true));
$this-redirect(array('action'='index'));
}

}

On Jul 24, 12:44 am, Vijay k.vidn...@gmail.com wrote:
 Hello All,

 I uploads the files to webroot/uploads folder from the file uploading
 component.

 Now I am trying to download that file from webroot/uploads folder but
 it is giving me 0 byte file.

 Code is as follows,

 function admin_download($id)
     {
         $this-adminchecksession();
             // you'll want to check the login status here ...

             $result = $this-Application-findById($id);

             Configure::write('debug', 0);
             $this-view = 'Media';

             /* MediaView is really irritating
              */
             //$name = $result['Application']['resume'];

             $ext = explode(. ,$result['Application']['resume']);

             $params = array(
                     'name' = $ext[0],
                     'download' = true,
                     'extension' = $ext[1],
                     'path' = APP.webroot/uploads.DS,
                     'mimeType' = array($result['Application']
 ['type'])
             );

             $this-set($params);

     }

 Please help me on this.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-24 Thread Vijay Kumbhar
i have removed that array too. but it is not still giving the file to
download.

On Fri, Jul 24, 2009 at 8:06 AM, brian bally.z...@gmail.com wrote:


 mimeType should be a string, not an array. Why do you assign it as
 array($result['Application']['type'])?

 On Thu, Jul 23, 2009 at 2:23 PM, Vijay Kumbhark.vidn...@gmail.com wrote:
  Hello Brian,
 
  Thanks for your reply.I have done as you told it gave me the $param
 values.
  But it is not giving me download window :( .
 
  here is code as you told to comment the part,
 
 //Configure::write('debug', 0);
 
  $this-view = 'Media';
 
  /* MediaView is really irritating
   */
  //$name = $result['Application']['resume'];
 
  $ext = explode(. ,$result['Application']['resume']);
 
  $params = array(
  'name' = $ext[0],
  'download' = true,
  'extension' = $ext[1],
  'path' = APP.webroot/uploads.DS,
  'mimeType' = array($result['Application']['type'])
  );
 
  $this-set($params);
 
  die(debug($params));
 
  And the output is as follows,
 
  app/controllers/applications_controller.php (line 198)
 
  Array
  (
  [name] = resume-1
  [download] = 1
  [extension] = doc
  [path] = MY_SERVER_DOCUMENT_PATH/app/webroot/uploads/
  [mimeType] = Array
  (
 
  [0] = application/msword
  )
 
  )
 
  Please help.
 
  On Thu, Jul 23, 2009 at 10:15 PM, brian bally.z...@gmail.com wrote:
 
  I like how you left my snarky comment in the code I'd posted :-)
 
  Try commenting out the Configure::write('debug', 0) and, after you've
  set the $params array, put:
 
  die(debug($params));
 
  ... so that you can see if the values are all what you're expecting.
 
  Of course, you should also ensure that the file is where you think it
  is and that the permissions allow the server to read it.
 
  On Thu, Jul 23, 2009 at 10:44 AM, Vijayk.vidn...@gmail.com wrote:
  
   Hello All,
  
   I uploads the files to webroot/uploads folder from the file uploading
   component.
  
   Now I am trying to download that file from webroot/uploads folder but
   it is giving me 0 byte file.
  
   Code is as follows,
  
   function admin_download($id)
  {
  $this-adminchecksession();
  // you'll want to check the login status here ...
  
  $result = $this-Application-findById($id);
  
  Configure::write('debug', 0);
  $this-view = 'Media';
  
  /* MediaView is really irritating
   */
  //$name = $result['Application']['resume'];
  
  $ext = explode(. ,$result['Application']['resume']);
  
  $params = array(
  'name' = $ext[0],
  'download' = true,
  'extension' = $ext[1],
  'path' = APP.webroot/uploads.DS,
  'mimeType' = array($result['Application']
   ['type'])
  );
  
  $this-set($params);
  
  }
  
  
   Please help me on this.
   
  
 
 
 
 
 
  --
  Thanks  Regards,
  Vijayk.
  Co-founder (www.weboniselab.com)
 
  You Bring the Dreams, We'll Bring the Means
 
  
 

 



-- 
Thanks  Regards,
Vijayk.
Co-founder (www.weboniselab.com)

You Bring the Dreams, We'll Bring the Means

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-24 Thread Rufus

I would imagine if you are getting an empty file you a referencing the
file incorrectly. Try echo out your path and make sure its correct.

make sure

On Jul 24, 5:39 pm, Vijay Kumbhar k.vidn...@gmail.com wrote:
 i have removed that array too. but it is not still giving the file to
 download.



 On Fri, Jul 24, 2009 at 8:06 AM, brian bally.z...@gmail.com wrote:

  mimeType should be a string, not an array. Why do you assign it as
  array($result['Application']['type'])?

  On Thu, Jul 23, 2009 at 2:23 PM, Vijay Kumbhark.vidn...@gmail.com wrote:
   Hello Brian,

   Thanks for your reply.I have done as you told it gave me the $param
  values.
   But it is not giving me download window :( .

   here is code as you told to comment the part,

              //Configure::write('debug', 0);

               $this-view = 'Media';

               /* MediaView is really irritating
                */
               //$name = $result['Application']['resume'];

               $ext = explode(. ,$result['Application']['resume']);

               $params = array(
                       'name' = $ext[0],
                       'download' = true,
                       'extension' = $ext[1],
                       'path' = APP.webroot/uploads.DS,
                       'mimeType' = array($result['Application']['type'])
               );

               $this-set($params);

               die(debug($params));

   And the output is as follows,

   app/controllers/applications_controller.php (line 198)

   Array
   (
       [name] = resume-1
       [download] = 1
       [extension] = doc
       [path] = MY_SERVER_DOCUMENT_PATH/app/webroot/uploads/
       [mimeType] = Array
           (

               [0] = application/msword
           )

   )

   Please help.

   On Thu, Jul 23, 2009 at 10:15 PM, brian bally.z...@gmail.com wrote:

   I like how you left my snarky comment in the code I'd posted :-)

   Try commenting out the Configure::write('debug', 0) and, after you've
   set the $params array, put:

   die(debug($params));

   ... so that you can see if the values are all what you're expecting.

   Of course, you should also ensure that the file is where you think it
   is and that the permissions allow the server to read it.

   On Thu, Jul 23, 2009 at 10:44 AM, Vijayk.vidn...@gmail.com wrote:

Hello All,

I uploads the files to webroot/uploads folder from the file uploading
component.

Now I am trying to download that file from webroot/uploads folder but
it is giving me 0 byte file.

Code is as follows,

function admin_download($id)
   {
       $this-adminchecksession();
           // you'll want to check the login status here ...

           $result = $this-Application-findById($id);

           Configure::write('debug', 0);
           $this-view = 'Media';

           /* MediaView is really irritating
            */
           //$name = $result['Application']['resume'];

           $ext = explode(. ,$result['Application']['resume']);

           $params = array(
                   'name' = $ext[0],
                   'download' = true,
                   'extension' = $ext[1],
                   'path' = APP.webroot/uploads.DS,
                   'mimeType' = array($result['Application']
['type'])
           );

           $this-set($params);

   }

Please help me on this.

   --
   Thanks  Regards,
   Vijayk.
   Co-founder (www.weboniselab.com)

   You Bring the Dreams, We'll Bring the Means

 --
 Thanks  Regards,
 Vijayk.
 Co-founder (www.weboniselab.com)

 You Bring the Dreams, We'll Bring the Means
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-24 Thread Vijay Kumbhar
Yeah...

Thanks rufus it works .

only i changed this line,

header('Content-Type: application/octet-stream'); to

header(Content-Type: .$result['Application']['resume']).);

that is the content type of the uploaded file coming from my database.


Thanks again...

On Fri, Jul 24, 2009 at 12:53 PM, Rufus rufusp...@gmail.com wrote:


 Here is my code:

 pdfDir is defined constant fyi


function download($id = null) {

if (!$id  empty($this-data)) {
$this-Session-setFlash(__('Invalid Invoice',
 true));
$this-redirect(array('action'='index'));
}

Configure::write('debug', 0);
$file = $this-Invoice-findById($id);
if (file_exists(pdfDir.$file['Invoice']['file_name'])) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename
 (pdfDir.$file['Invoice']['file_name']));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-
 check=0');
header('Pragma: public');
header('Content-Length: ' . filesize(pdfDir.$file['Invoice']
 ['file_name']));
ob_clean();
flush();
readfile(pdfDir.$file['Invoice']['file_name']);
exit;
} else {
$this-Session-setFlash(__('File Does Not Exist',
 true));
$this-redirect(array('action'='index'));
 }

}

 On Jul 24, 12:44 am, Vijay k.vidn...@gmail.com wrote:
  Hello All,
 
  I uploads the files to webroot/uploads folder from the file uploading
  component.
 
  Now I am trying to download that file from webroot/uploads folder but
  it is giving me 0 byte file.
 
  Code is as follows,
 
  function admin_download($id)
  {
  $this-adminchecksession();
  // you'll want to check the login status here ...
 
  $result = $this-Application-findById($id);
 
  Configure::write('debug', 0);
  $this-view = 'Media';
 
  /* MediaView is really irritating
   */
  //$name = $result['Application']['resume'];
 
  $ext = explode(. ,$result['Application']['resume']);
 
  $params = array(
  'name' = $ext[0],
  'download' = true,
  'extension' = $ext[1],
  'path' = APP.webroot/uploads.DS,
  'mimeType' = array($result['Application']
  ['type'])
  );
 
  $this-set($params);
 
  }
 
  Please help me on this.
 



-- 
Thanks  Regards,
Vijayk.
Co-founder (www.weboniselab.com)

You Bring the Dreams, We'll Bring the Means

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-24 Thread Vijay Kumbhar
Also i have created a code  it also worked  :)

// your file to upload
  $result = $this-Application-findById($id);

  // your file to upload
  $file = APP.webroot/uploads.DS.$result['Application']['resume'];
  header(Pragma: public);
  header(Expires: 0);
  header(Cache-Control: must-revalidate, post-check=0,
pre-check=0);
  header(Cache-Control: private,false);
  header(Content-Type: .$result['Application']['type']. );
  header(Content-Disposition: attachment;
filename=\.$result['Application']['resume'].\;);
  header(Content-Transfer-Encoding:­ binary);
  //header(Content-Length: .$filesize);
  readfile($file);
  exit;



On Fri, Jul 24, 2009 at 1:28 PM, Vijay Kumbhar k.vidn...@gmail.com wrote:

 Yeah...

 Thanks rufus it works .

 only i changed this line,

 header('Content-Type: application/octet-stream'); to

 header(Content-Type: .$result['Application']['resume']).);

 that is the content type of the uploaded file coming from my database.


 Thanks again...


 On Fri, Jul 24, 2009 at 12:53 PM, Rufus rufusp...@gmail.com wrote:


 Here is my code:

 pdfDir is defined constant fyi


function download($id = null) {

if (!$id  empty($this-data)) {
$this-Session-setFlash(__('Invalid Invoice',
 true));
$this-redirect(array('action'='index'));
}

Configure::write('debug', 0);
$file = $this-Invoice-findById($id);
if (file_exists(pdfDir.$file['Invoice']['file_name'])) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename
 (pdfDir.$file['Invoice']['file_name']));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-
 check=0');
header('Pragma: public');
header('Content-Length: ' . filesize(pdfDir.$file['Invoice']
 ['file_name']));
ob_clean();
flush();
readfile(pdfDir.$file['Invoice']['file_name']);
exit;
} else {
$this-Session-setFlash(__('File Does Not Exist',
 true));
$this-redirect(array('action'='index'));
 }

}

 On Jul 24, 12:44 am, Vijay k.vidn...@gmail.com wrote:
  Hello All,
 
  I uploads the files to webroot/uploads folder from the file uploading
  component.
 
  Now I am trying to download that file from webroot/uploads folder but
  it is giving me 0 byte file.
 
  Code is as follows,
 
  function admin_download($id)
  {
  $this-adminchecksession();
  // you'll want to check the login status here ...
 
  $result = $this-Application-findById($id);
 
  Configure::write('debug', 0);
  $this-view = 'Media';
 
  /* MediaView is really irritating
   */
  //$name = $result['Application']['resume'];
 
  $ext = explode(. ,$result['Application']['resume']);
 
  $params = array(
  'name' = $ext[0],
  'download' = true,
  'extension' = $ext[1],
  'path' = APP.webroot/uploads.DS,
  'mimeType' = array($result['Application']
  ['type'])
  );
 
  $this-set($params);
 
  }
 
  Please help me on this.
 



 --
 Thanks  Regards,
 Vijayk.
 Co-founder (www.weboniselab.com)

 You Bring the Dreams, We'll Bring the Means




-- 
Thanks  Regards,
Vijayk.
Co-founder (www.weboniselab.com)

You Bring the Dreams, We'll Bring the Means

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-24 Thread Crazy

Will there be allot of file downloads?

If there will be a big load on the site from file downloads,
especially big files. Then it's not smart to handle it in cakephp.
Especially if you want to support download accellerators/resume
support

On every request(someone that uses a download accelerator and makes 10
requests), the cakephp framework is loaded.
This is accually not needed, because it's a plain file download.
Even if you want to check a couple of things in the database, it's
better to do it manually.

This ofcouse depends on the situation you're in.
In my case, using cakephp this way would crash my server within 5
minutes(if not faster)

You can find the code I use here:

http://pastebin.com/f179e1e49

I've been using it for several years and transfer 15 to 20tb per month
using that piece of code.


/Crazy

On Jul 24, 9:58 am, Vijay Kumbhar k.vidn...@gmail.com wrote:
 Yeah...

 Thanks rufus it works .

 only i changed this line,

 header('Content-Type: application/octet-stream'); to

 header(Content-Type: .$result['Application']['resume']).);

 that is the content type of the uploaded file coming from my database.

 Thanks again...



 On Fri, Jul 24, 2009 at 12:53 PM, Rufus rufusp...@gmail.com wrote:

  Here is my code:

  pdfDir is defined constant fyi

         function download($id = null) {

                 if (!$id  empty($this-data)) {
                         $this-Session-setFlash(__('Invalid Invoice',
  true));
                         $this-redirect(array('action'='index'));
                 }

                 Configure::write('debug', 0);
                 $file = $this-Invoice-findById($id);
     if (file_exists(pdfDir.$file['Invoice']['file_name'])) {
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename='.basename
  (pdfDir.$file['Invoice']['file_name']));
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-
  check=0');
         header('Pragma: public');
         header('Content-Length: ' . filesize(pdfDir.$file['Invoice']
  ['file_name']));
         ob_clean();
         flush();
         readfile(pdfDir.$file['Invoice']['file_name']);
         exit;
     } else {
                         $this-Session-setFlash(__('File Does Not Exist',
  true));
                         $this-redirect(array('action'='index'));
      }

         }

  On Jul 24, 12:44 am, Vijay k.vidn...@gmail.com wrote:
   Hello All,

   I uploads the files to webroot/uploads folder from the file uploading
   component.

   Now I am trying to download that file from webroot/uploads folder but
   it is giving me 0 byte file.

   Code is as follows,

   function admin_download($id)
       {
           $this-adminchecksession();
               // you'll want to check the login status here ...

               $result = $this-Application-findById($id);

               Configure::write('debug', 0);
               $this-view = 'Media';

               /* MediaView is really irritating
                */
               //$name = $result['Application']['resume'];

               $ext = explode(. ,$result['Application']['resume']);

               $params = array(
                       'name' = $ext[0],
                       'download' = true,
                       'extension' = $ext[1],
                       'path' = APP.webroot/uploads.DS,
                       'mimeType' = array($result['Application']
   ['type'])
               );

               $this-set($params);

       }

   Please help me on this.

 --
 Thanks  Regards,
 Vijayk.
 Co-founder (www.weboniselab.com)

 You Bring the Dreams, We'll Bring the Means
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-24 Thread Vijay Kumbhar
Hey Crazy,

thanks a lot ... i will try this out.


On Fri, Jul 24, 2009 at 1:56 PM, Crazy crazy...@gmail.com wrote:


 Will there be allot of file downloads?

 If there will be a big load on the site from file downloads,
 especially big files. Then it's not smart to handle it in cakephp.
 Especially if you want to support download accellerators/resume
 support

 On every request(someone that uses a download accelerator and makes 10
 requests), the cakephp framework is loaded.
 This is accually not needed, because it's a plain file download.
 Even if you want to check a couple of things in the database, it's
 better to do it manually.

 This ofcouse depends on the situation you're in.
 In my case, using cakephp this way would crash my server within 5
 minutes(if not faster)

 You can find the code I use here:

 http://pastebin.com/f179e1e49

 I've been using it for several years and transfer 15 to 20tb per month
 using that piece of code.


 /Crazy

 On Jul 24, 9:58 am, Vijay Kumbhar k.vidn...@gmail.com wrote:
  Yeah...
 
  Thanks rufus it works .
 
  only i changed this line,
 
  header('Content-Type: application/octet-stream'); to
 
  header(Content-Type: .$result['Application']['resume']).);
 
  that is the content type of the uploaded file coming from my database.
 
  Thanks again...
 
 
 
  On Fri, Jul 24, 2009 at 12:53 PM, Rufus rufusp...@gmail.com wrote:
 
   Here is my code:
 
   pdfDir is defined constant fyi
 
  function download($id = null) {
 
  if (!$id  empty($this-data)) {
  $this-Session-setFlash(__('Invalid Invoice',
   true));
  $this-redirect(array('action'='index'));
  }
 
  Configure::write('debug', 0);
  $file = $this-Invoice-findById($id);
  if (file_exists(pdfDir.$file['Invoice']['file_name'])) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename
   (pdfDir.$file['Invoice']['file_name']));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-
   check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize(pdfDir.$file['Invoice']
   ['file_name']));
  ob_clean();
  flush();
  readfile(pdfDir.$file['Invoice']['file_name']);
  exit;
  } else {
  $this-Session-setFlash(__('File Does Not
 Exist',
   true));
  $this-redirect(array('action'='index'));
   }
 
  }
 
   On Jul 24, 12:44 am, Vijay k.vidn...@gmail.com wrote:
Hello All,
 
I uploads the files to webroot/uploads folder from the file uploading
component.
 
Now I am trying to download that file from webroot/uploads folder but
it is giving me 0 byte file.
 
Code is as follows,
 
function admin_download($id)
{
$this-adminchecksession();
// you'll want to check the login status here ...
 
$result = $this-Application-findById($id);
 
Configure::write('debug', 0);
$this-view = 'Media';
 
/* MediaView is really irritating
 */
//$name = $result['Application']['resume'];
 
$ext = explode(. ,$result['Application']['resume']);
 
$params = array(
'name' = $ext[0],
'download' = true,
'extension' = $ext[1],
'path' = APP.webroot/uploads.DS,
'mimeType' = array($result['Application']
['type'])
);
 
$this-set($params);
 
}
 
Please help me on this.
 
  --
  Thanks  Regards,
  Vijayk.
  Co-founder (www.weboniselab.com)
 
  You Bring the Dreams, We'll Bring the Means
 



-- 
Thanks  Regards,
Vijayk.
Co-founder (www.weboniselab.com)

You Bring the Dreams, We'll Bring the Means

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Download code for downloading a file

2009-07-23 Thread Vijay

Hello All,

I uploads the files to webroot/uploads folder from the file uploading
component.

Now I am trying to download that file from webroot/uploads folder but
it is giving me 0 byte file.

Code is as follows,

function admin_download($id)
{
$this-adminchecksession();
// you'll want to check the login status here ...

$result = $this-Application-findById($id);

Configure::write('debug', 0);
$this-view = 'Media';

/* MediaView is really irritating
 */
//$name = $result['Application']['resume'];

$ext = explode(. ,$result['Application']['resume']);

$params = array(
'name' = $ext[0],
'download' = true,
'extension' = $ext[1],
'path' = APP.webroot/uploads.DS,
'mimeType' = array($result['Application']
['type'])
);

$this-set($params);

}


Please help me on this.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-23 Thread brian

I like how you left my snarky comment in the code I'd posted :-)

Try commenting out the Configure::write('debug', 0) and, after you've
set the $params array, put:

die(debug($params));

... so that you can see if the values are all what you're expecting.

Of course, you should also ensure that the file is where you think it
is and that the permissions allow the server to read it.

On Thu, Jul 23, 2009 at 10:44 AM, Vijayk.vidn...@gmail.com wrote:

 Hello All,

 I uploads the files to webroot/uploads folder from the file uploading
 component.

 Now I am trying to download that file from webroot/uploads folder but
 it is giving me 0 byte file.

 Code is as follows,

 function admin_download($id)
    {
        $this-adminchecksession();
            // you'll want to check the login status here ...

            $result = $this-Application-findById($id);

            Configure::write('debug', 0);
            $this-view = 'Media';

            /* MediaView is really irritating
             */
            //$name = $result['Application']['resume'];

            $ext = explode(. ,$result['Application']['resume']);

            $params = array(
                    'name' = $ext[0],
                    'download' = true,
                    'extension' = $ext[1],
                    'path' = APP.webroot/uploads.DS,
                    'mimeType' = array($result['Application']
 ['type'])
            );

            $this-set($params);

    }


 Please help me on this.
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-23 Thread Vijay Kumbhar
Hello Brian,

Thanks for your reply.I have done as you told it gave me the $param values.
But it is not giving me download window :( .

here is code as you told to comment the part,

   //Configure::write('debug', 0);

$this-view = 'Media';

/* MediaView is really irritating
 */
//$name = $result['Application']['resume'];

$ext = explode(. ,$result['Application']['resume']);

$params = array(
'name' = $ext[0],
'download' = true,
'extension' = $ext[1],
'path' = APP.webroot/uploads.DS,
'mimeType' = array($result['Application']['type'])
);

$this-set($params);

die(debug($params));

And the output is as follows,

*app/controllers/applications_controller.php* (line *198*)

Array
(
[name] = resume-1
[download] = 1
[extension] = doc
[path] = MY_SERVER_DOCUMENT_PATH/app/webroot/uploads/
[mimeType] = Array
(
[0] = application/msword
)

)

Please help.

On Thu, Jul 23, 2009 at 10:15 PM, brian bally.z...@gmail.com wrote:


 I like how you left my snarky comment in the code I'd posted :-)

 Try commenting out the Configure::write('debug', 0) and, after you've
 set the $params array, put:

 die(debug($params));

 ... so that you can see if the values are all what you're expecting.

 Of course, you should also ensure that the file is where you think it
 is and that the permissions allow the server to read it.

 On Thu, Jul 23, 2009 at 10:44 AM, Vijayk.vidn...@gmail.com wrote:
 
  Hello All,
 
  I uploads the files to webroot/uploads folder from the file uploading
  component.
 
  Now I am trying to download that file from webroot/uploads folder but
  it is giving me 0 byte file.
 
  Code is as follows,
 
  function admin_download($id)
 {
 $this-adminchecksession();
 // you'll want to check the login status here ...
 
 $result = $this-Application-findById($id);
 
 Configure::write('debug', 0);
 $this-view = 'Media';
 
 /* MediaView is really irritating
  */
 //$name = $result['Application']['resume'];
 
 $ext = explode(. ,$result['Application']['resume']);
 
 $params = array(
 'name' = $ext[0],
 'download' = true,
 'extension' = $ext[1],
 'path' = APP.webroot/uploads.DS,
 'mimeType' = array($result['Application']
  ['type'])
 );
 
 $this-set($params);
 
 }
 
 
  Please help me on this.
  
 

 



-- 
Thanks  Regards,
Vijayk.
Co-founder (www.weboniselab.com)

You Bring the Dreams, We'll Bring the Means

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Download code for downloading a file

2009-07-23 Thread brian

mimeType should be a string, not an array. Why do you assign it as
array($result['Application']['type'])?

On Thu, Jul 23, 2009 at 2:23 PM, Vijay Kumbhark.vidn...@gmail.com wrote:
 Hello Brian,

 Thanks for your reply.I have done as you told it gave me the $param values.
 But it is not giving me download window :( .

 here is code as you told to comment the part,

    //Configure::write('debug', 0);

     $this-view = 'Media';

     /* MediaView is really irritating
  */
     //$name = $result['Application']['resume'];

     $ext = explode(. ,$result['Application']['resume']);

     $params = array(
     'name' = $ext[0],
     'download' = true,
     'extension' = $ext[1],
     'path' = APP.webroot/uploads.DS,
     'mimeType' = array($result['Application']['type'])
     );

     $this-set($params);

     die(debug($params));

 And the output is as follows,

 app/controllers/applications_controller.php (line 198)

 Array
 (
 [name] = resume-1
 [download] = 1
 [extension] = doc
 [path] = MY_SERVER_DOCUMENT_PATH/app/webroot/uploads/
 [mimeType] = Array
 (

 [0] = application/msword
 )

 )

 Please help.

 On Thu, Jul 23, 2009 at 10:15 PM, brian bally.z...@gmail.com wrote:

 I like how you left my snarky comment in the code I'd posted :-)

 Try commenting out the Configure::write('debug', 0) and, after you've
 set the $params array, put:

 die(debug($params));

 ... so that you can see if the values are all what you're expecting.

 Of course, you should also ensure that the file is where you think it
 is and that the permissions allow the server to read it.

 On Thu, Jul 23, 2009 at 10:44 AM, Vijayk.vidn...@gmail.com wrote:
 
  Hello All,
 
  I uploads the files to webroot/uploads folder from the file uploading
  component.
 
  Now I am trying to download that file from webroot/uploads folder but
  it is giving me 0 byte file.
 
  Code is as follows,
 
  function admin_download($id)
     {
         $this-adminchecksession();
             // you'll want to check the login status here ...
 
             $result = $this-Application-findById($id);
 
             Configure::write('debug', 0);
             $this-view = 'Media';
 
             /* MediaView is really irritating
              */
             //$name = $result['Application']['resume'];
 
             $ext = explode(. ,$result['Application']['resume']);
 
             $params = array(
                     'name' = $ext[0],
                     'download' = true,
                     'extension' = $ext[1],
                     'path' = APP.webroot/uploads.DS,
                     'mimeType' = array($result['Application']
  ['type'])
             );
 
             $this-set($params);
 
     }
 
 
  Please help me on this.
  
 





 --
 Thanks  Regards,
 Vijayk.
 Co-founder (www.weboniselab.com)

 You Bring the Dreams, We'll Bring the Means

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---