play media file or open image in browser cakephp -


i using cakephp 2.x want play audio , open image in browser ....

in 'view' have following code correctly showing filename, , displaying download link , file downloading

 <?php  echo $this->html->link('download', array('controller' => 'bugshot', 'action' => 'download', $files['audio']['filename']));?> 

now want play audio file ..as have 2 licks on page ,,, first download , tthe other view or play

in controller have following code downloading file

      public function download($filename) {      $iduser = $this->auth->user('iduser');     $folder_url = app.'uploads/'.$iduser.'/'.$filename;     $this->response->file($folder_url, array('download' => true, 'name' => $filename));      return $this->response; } 

downloading , serving files same

serving files via cake can done 1 function similiar following:

public function download($filename) {     $download = !empty($_get['download']); // <- example      $iduser = $this->auth->user('iduser');     $folder_url = app.'uploads/'.$iduser.'/'.$filename;     $this->response->file($folder_url, array('download' => $download, 'name' => $filename));     return $this->response; } 

that way requesting url /.../this-file.mp3 serve file, whereas url /.../this-file.mp3?dowload=1 download it.

audio html5 tag

the simplest way serve audio, use audio tag:

<?php     $url = router::url(array('controller' => 'x', 'action' => 'download', $name));     $download = router::url(array('controller' => 'x', 'action' => 'download', $name, '?' => array('download' => 1))); ?> <audio src="<?= $url; ?>" controls> <!-- alternate content unsupported case --> download <a href="<?= $download ?>">download it</a>; </audio> 

being relatively new tag, support isn't universal - see detailed article on support or other resources more information on how handle browsers not support tag.

or, use 1 of many flash based media players exist.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -