Pergunta

I want to upload audio files (type mp3,acc,wav) I am using cakephp 2.4.1 stable and php5 stable. I have tried mime_content_type,finfo_file to check if uploaded file is audio file with either mp3,acc or wav type. But I get this

`error mime_content_type(059.piya basanti re... [piya basanti][2000].mp3): failed to open stream: No such file or directory [APP/Controller/AdminController.php, line 86]`

My app dir and webroot dir are permited with 0777.

Here is my view.ctp code :

<?= $this->Form->create('Homepage',array('type'=>'file'));
echo $this->Form->input('audio_1',array('type'=>'file'));
echo $this->Form->submit('Submit');
echo $this->Form->end(); ?>

my Controller code

    public function saveaudio() {
            if($this->request->is('post')) {
                $this->loadModel('Homepage');
//this is line 86//   $file = mime_content_type($this->request->data['Homepage']['audio_1']['name']);
                 pr($file);exit;
              }

and here is my data

Array
(
    [Homepage] => Array
        (
            [audio_1] => Array
                (
                    [name] => 059.piya basanti re... [piya basanti][2000].mp3
                    [type] => 
                    [tmp_name] => 
                    [error] => 1
                    [size] => 0
                )

        )
)

My question is :

  1. How I can check type of file? First I want to check its mime type then I want to save it
  2. Why I am not getting tmp_name for uploaded file?
  3. Why I am getting error for mime_content_type?

Can anyone explain me? It would be helpfull to me

Foi útil?

Solução

Look at the data, the upload was discarded as there's an error. 1 equals UPLOAD_ERR_INI_SIZE, and the cause for this is:

The uploaded file exceeds the upload_max_filesize directive in php.ini.

See http://php.net/manual/features.file-upload.errors.php

So you have to increase that value, and most probably also post_max_size, see http://php.net/manual/features.file-upload.common-pitfalls.php for more information.

And once the uploading works, you'll have to use the correct keys, it's audio_1, not audio_, also you'll then have to use tmp_name, ie this:

$this->request->data['Homepage']['audio_']['name']

should be this

$this->request->data['Homepage']['audio_1']['tmp_name']

On a side note, mime_content_type is deprecated in favour of the Fileinfo extension.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top