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.