Cupfileupload Problem

I recently upgraded my server from OpenSUSE 12.1 to 13.1, upgrading apache to 2.4.6 and php to 5.4.20. mod_mime.so is enabled. I think the old set up apache 2.? and php 5.3.8.

I have a site that uploaded mp3 files to for podcasts and it worked fine. Now I get a 500 error, unable to open stream, when checking the mime_type with CFileHelper.

In Post model:




    private $_uploadedFile;

    public $uploadedFile;


    public function rules() {

        // NOTE: you should only define rules for those attributes that

        // will receive user inputs.

        return array(

            ...

            array('uploadedFile', 'file', 'allowEmpty' => 'true', 'types' => 'mp3', 'maxSize' => 1024 * 1024 * 50, 'tooLarge' => 'File has to be smaller than 50MB'),

            ...

        );

    }


    protected function beforeSave() {

        if (parent::beforeSave()) {

            if (!isset($this->date_aired)) {

                $this->setAttribute('date_aired', time());

            } else {

                $this->setAttribute('date_aired', strtotime($this->date_aired));

            }

            if (trim($this->guest_position) == '') {

                $this->setAttribute('guest_position', null);

            }

            if (trim($this->tags) == '') {

                $this->setAttribute('tags', null);

            }


            // Get the Uploaded File information

            $this->_uploadedFile = CUploadedFile::getInstance($this, 'uploadedFile');


            if ($this->_uploadedFile !== null) {

                if (trim($this->file_name) == '') {

                    $this->setAttribute('file_name', $this->generateFileName(CFileHelper::getExtension($this->_uploadedFile->name)));

                }

                $this->setAttribute('file_type', CFileHelper::getMimeType($this->_uploadedFile->name));

                $this->setAttribute('file_size', $this->_uploadedFile->size);

            } //EndIf($this->_uploadedFile!==null)


            if ($this->isNewRecord) {

                $this->create_time = $this->update_time = time();

                $this->posted_by = Yii::app()->user->name;

            } else {

                $this->update_time = time();

            }

            return true;

        } else {

            return false;

        } //EndIf(parent::beforeSave())

    }


    protected function afterSave() {

        //Save the Audio File

        if ($this->_uploadedFile) {

            $_dir = $this->getPodcastPath();


            if (!file_exists($_dir)) {

                mkdir($_dir, 0777, true);

            }


            $this->_uploadedFile->saveAs($_dir . '/' . $this->file_name);

        } //EndIf($this_uploadedFile)


        parent::afterSave();

        Tag::model()->updateFrequency($this->_oldTags, $this->tags);

    }



I checked the value of $this->_uploadedFile after the getInstance() line and ->tempName is just a directory/php(randomId) with no extension. I tried use tempName in the mimeType() call and got back ‘application/octet’, or something similar.

Did php change the way it handles file uploads? Any ideas on how to get accurate mime_types?

Thanks in advance.

CUploadedFile already provide you MIME type in "type" attribute (http://www.yiiframework.com/doc/api/1.1/CUploadedFile#type-detail), you do not need to determine it by yourself…

From the reference you gave:[quote name=‘Documents’]Since this MIME type is not checked on the server side, do not take this value for granted. Instead, use CFileHelper::getMimeType to determine the exact MIME type.
[/quote]

Maybe, but I have never seen case when mime type was not provided by the browser with uploaded file…

Mime type provided by the browser: Yes. Same one for an mp3: No. It depends on the OS as to what the browser sends. I have seen 3 different mime_types for an mp3.