Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

CakePHP pdf download file corrupted

[es] :: PHP :: CakePHP pdf download file corrupted

[ Pregleda: 1596 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

pecooou
Petar Jovanovic
Nis

Član broj: 69500
Poruke: 134
91.74.61.*

Sajt: www.pecooou.com


Profil

icon CakePHP pdf download file corrupted01.07.2014. u 09:21 - pre 119 meseci
Kada downloadujem PDF prikazuje da je dokument corrupted.

Evo koda iz PagesController:

Code:

    public function download($filename = null) {
        
        // Check if a filename was specified
        if (is_null($filename)) {
            $this->Session->setFlash('Sorry, no file was specified for download.');
            $this->redirect($this->referer());
        }
        
        $this->viewClass = 'Media';
        
        // Split the filename into it's constituent parts, i.e. the name and the extension
        $pathinfo = pathinfo($filename);
        
        $params = array(
            'id' => $filename,
            'name' => $pathinfo['filename'],
            'extension' => $pathinfo['extension'],
            'path' => 'downloads' . DS,
            'download' => true,
            'mimeType' => $this->__getMimeType($pathinfo['extension'])
        );
        
        $this->set($params);
        
    }
    
    /**
     * __getMimeType function.
     * 
     * @access private
     * @param mixed $extension
     * @return void
     */
    private function __getMimeType($extension) {
        
        switch ($extension) {
            case "pdf":
                return "application/pdf";
                break;    
        }
        
    }




Ako bi neko mogao da pomogne, puno bi mi znacilo.

P.S. Verzija Cakea je 2.3.

 
Odgovor na temu

drjekyll87
Nis

Član broj: 324735
Poruke: 1
*.static.sbb.rs.



Profil

icon Re: CakePHP pdf download file corrupted21.08.2014. u 13:58 - pre 117 meseci
mozes da download-ujes pdf i pomocu ove f-je, da ne koristis Media

public function downloadPdf($fileName) {

$path = APP . 'Vendor' . DS . 'pdf' . DS . $fileName . '.pdf'; //full path to file
$this->response->file($path, array(
'download' => true,
'name' => $fileName,
));
return $this->response;
}
 
Odgovor na temu

[es] :: PHP :: CakePHP pdf download file corrupted

[ Pregleda: 1596 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.