0

I have an application were by users can upload images and should be able to echo and play videos. My upload function works fine but challenge that i am having now is to echo and play the video. Here is how i am uploading the file

function uploadFile() {
    $file = $this->data['CpdVideo']['file'];
    if ($file['error'] === UPLOAD_ERR_OK) {
        $id = String::uuid();
        if (move_uploaded_file($file['tmp_name'], WWW_ROOT . 'files/videos/' . $file['name'])) {
            $this->request->data['CpdVideo']['filename'] = $file['name'];
            $this->request->data['CpdVideo']['filesize'] = $file['size'];
            $this->request->data['CpdVideo']['filemime'] = $file['type'];
            return true;
        }
    }
    return false;
}

Here is how i am saving the video

if ($this->uploadFile() && $this->CpdVideo->save($this->data))

This how i echo and play the video in my view.ctp. Please not this edited code and this works for me now

<object width="100" height="100">
<param name="movie" value="<?php echo $this->Html->url('/files/videos/'. $cpdVideo['CpdVideo']['filename'])?>">
<embed src="<?php echo $this->Html->url('/files/videos/'. $cpdVideo['CpdVideo']['filename'])?>" width="100" height="100">
</embed>
</object> 

If any one could help me out that would be awesome

Victor M
  • 23
  • 1
  • 4
  • 11
  • What does `Html->media('files/videos'. $cpdVideo['CpdVideo']['filename'], array('fullBase' => true));` print out? – yourdeveloperfriend Feb 28 '13 at 08:43
  • @yourdeveloperfriend only leaves a space and doesnt print anything. – Victor M Feb 28 '13 at 08:50
  • Once you got the basic thing working, please do some reading about file upload security - [it's complicated](https://www.owasp.org/index.php/Unrestricted_File_Upload). In your current setup, somebody could just upload their own `.php` and execute it _on your server_, because it is in the public webroot folder. – pixelistik Feb 28 '13 at 09:01
  • Another good starting point about file upload security: http://stackoverflow.com/a/11061577/376138 – pixelistik Feb 28 '13 at 09:16

1 Answers1

0

Try modifying this line

<?php echo $this->Html->media('files/videos'. $cpdVideo['CpdVideo']['filename'], array('fullBase' => true)); 

to

<?php echo $this->Html->media('files/videos'. $cpdVideo['CpdVideo']['filename'], array('fullBase' => true, type="audio/ogg")); 

Where ogg is the filetype of that file. The issue is that without that filetype, then some browsers will strip it out of your html (if you view the page source, you may find your audio tag sitting there).

I don't know if CakePHP provides some way to guess the filetype, but it would be worth looking into. I hope I've pointed you in the right direction.

yourdeveloperfriend
  • 1,600
  • 1
  • 9
  • 19