Source for file Ethna_Plugin_Validator_File.php
Documentation is available at Ethna_Plugin_Validator_File.php
// vim: foldmethod=marker
* Ethna_Plugin_Validator_File.php
* @author ICHII Takashi <ichii386@schweetheart.jp>
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
if (defined('UPLOAD_ERR_OK') ==
false) { // PHP 4.3.0
if (defined('UPLOAD_ERR_INI_SIZE') ==
false) { // PHP 4.3.0
define('UPLOAD_ERR_INI_SIZE', 1);
if (defined('UPLOAD_ERR_FORM_SIZE') ==
false) { // PHP 4.3.0
define('UPLOAD_ERR_FORM_SIZE', 2);
if (defined('UPLOAD_ERR_PARTIAL') ==
false) { // PHP 4.3.0
define('UPLOAD_ERR_PARTIAL', 3);
if (defined('UPLOAD_ERR_NO_FILE') ==
false) { // PHP 4.3.0
define('UPLOAD_ERR_NO_FILE', 4);
if (defined('UPLOAD_ERR_NO_TMP_DIR') ==
false) { // PHP 4.3.10, 5.0.3
define('UPLOAD_ERR_NO_TMP_DIR', 6);
if (defined('UPLOAD_ERR_CANT_WRITE') ==
false) { // PHP 5.1.0
define('UPLOAD_ERR_CANT_WRITE', 7);
// {{{ Ethna_Plugin_Validator_File
* @author ICHII Takashi <ichii386@schweetheart.jp>
/** @var bool 配列を受け取るかフラグ */
* @param string $name フォームの名前
* @param mixed $var フォームの値
* @param array $params プラグインのパラメータ
function &validate($name, $var, $params)
// そもそもアップロードされていない場合はスキップ
$msg =
_et("Uploaded file size exceeds php.ini's upload_max_filesize directive.");
$msg =
_et('Uploaded File size exceeds MAX_FILE_SIZE specified in HTML Form.');
$msg=
_et('File was only uploaded patially.');
$msg =
_et('File was not uploaded.');
$msg =
_et('Temporary folder was not found.');
$msg=
_et('Could not write uploaded file to disk.');
if (isset
($params['error'])) {
if (isset
($var['tmp_name']) ==
false ||
is_uploaded_file($var['tmp_name']) ==
false) {
if (isset
($params['error'])) {
$msg =
_et('invalid tmp_name.');
if (isset
($params['size_max'])) {
$st =
stat($var['tmp_name']);
if (isset
($params['error'])) {
$msg =
_et('Uploaded file size must be less than %s.');
if (isset
($params['size_min'])) {
$st =
stat($var['tmp_name']);
if (isset
($params['error'])) {
$msg =
_et('Uploaded file size must be more than %s.');
if (isset
($params['type'])) {
$posted_mime =
explode('/', $var['type'], 2);
foreach ($type_list as $type) {
$wanted_mime =
explode('/', $type, 2);
$test =
(count($wanted_mime) ==
1)
?
(strcasecmp($wanted_mime[0], $posted_mime[0]) ==
0)
if (isset
($params['error'])) {
$msg =
_et('Invalid file type.');
if (isset
($params['name'])) {
$test =
($params['name']{0} ==
'/')
:
(strcmp($params['name'], $var['name']) ==
0);
if (isset
($params['error'])) {
$msg =
_et('Invalid file name.');
if (preg_match('/^([0-9]+)([mk])?(b(ytes?)?)?$/i', trim($size), $matches)) {
if (isset
($matches[1])) {
if (isset
($matches[2])) {
return intval($matches[1]) *
$unit;
Documentation generated on Fri, 11 Nov 2011 04:00:40 +0900 by phpDocumentor 1.4.3