/** * Create new string */ public function actionAddString() { // Check Access checkAccessThrowException('op_language_add_strings'); $model = new SourceMessage(); if (isset($_POST['SourceMessage'])) { $model->attributes = $_POST['SourceMessage']; if ($model->save()) { Language::model()->syncAllLanguages(); fok(at('String Created.')); alog(at("Added New String '{name}'", array('{name}' => $model->message))); $this->redirect(array('language/index')); } } // Add Breadcrumb $this->addBreadCrumb(at('Creating New String')); $this->title[] = at('Creating New String'); finfo(at('Strings will be added to source table then the languages will be synced to have that newly created string included in each language.')); // Display form $this->render('string_form', array('model' => $model)); }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if the file is compression with the set compression types * * @param string $value Real file to check for compression * @param array $file File data from Zend_File_Transfer * @return boolean */ public function isValid($value, $file = null) { // Is file readable ? if (!@is_readable($value)) { $this->_throw($file, self::NOT_READABLE); return false; } if (class_exists('fileinfo')) { $info = finfo(FILEINFO_MIME); $this->_type = $info->file($value); $info->close(); } else { if (function_exists('mime_content_type')) { $this->_type = mime_content_type($value); } } if (empty($this->_type) and $file !== null) { $this->_type = $file['type']; } if (empty($this->_type)) { $this->_throw($file, self::NOT_DETECTED); return false; } $compressions = $this->getMimeType(true); if (in_array($this->_type, $compressions)) { return true; } foreach ($compressions as $mime) { $types = explode('/', $this->_type); $types = array_merge($types, explode('-', $this->_type)); if (in_array($mime, $types)) { return true; } } $this->_throw($file, self::FALSE_TYPE); return false; }
<!-- send file to browser --> <?php session_start(); $filename = $_GET['file']; if (!preg_match('/^[\\w_\\.\\-]+$/', $filename)) { echo "Invalid filename"; exit; } $username = $_SESSION['username']; if (!preg_match('/^[\\w_\\-]+$/', $username)) { echo "Invalid username"; exit; } $full_path = sprintf("/srv/uploads/%s/%s", $username, $filename); $finfo = finfo(FILEINFO_MINE_TYPE); $mime = $finfo->file($full_path); header("Content-Type: " . $mime); readfile($full_path); ?> <!-- upload file --> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <p> <input type="hidden" name="MAX_FILE_SIZE" value="20000000" /> <label for="uploadfile_input">Choose a file to upload:</label> <input name="uploadedfile" type="file" id="uploadfile_input" /> </p> <p> <input type="submit" value="Upload File" /> </p>
/** * Return the file mime type * @param string $file File path * @return string|boolean */ public static function _getMIME($file) { // Check file exists if (!self::_Exists($file)) { return FALSE; } // Open file $finfo = finfo(); // If file could not be opened if ($finfo === FALSE) { // Set error new \Sonic\Message('error', 'Could not get file MIME type: ' . $file); // Return FALSE return FALSE; } // Return mime type return $finfo->file($file); }