Skip to content

Instantly share code, notes, and snippets.

@k1ic
Created January 30, 2015 05:43
Show Gist options
  • Save k1ic/18f3db458fe73ed40153 to your computer and use it in GitHub Desktop.
Save k1ic/18f3db458fe73ed40153 to your computer and use it in GitHub Desktop.
判断文件上传是否成功
if (!empty($_FILES)) {
switch ($_FILES['voice']['error']) {
case UPLOAD_ERR_OK: //上传成功
if (!in_array(Tool_PublicPlatform::get_file_type($_FILES['voice']['tmp_name']), self::$_audioType)) {
$res = Comm_I18n::text('ajax.publicplatform.illegal_file_type');
} elseif ($_FILES['voice']['size'] > self::MAX_AUDIO_FILE_SIZE) {
$res = Comm_I18n::text('ajax.publicplatform.more_than_max') . '1M...';
} elseif ($_FILES['voice']['size'] == 0) {
$res = Comm_I18n::text('ajax.publicplatform.file_size_0M');
} else {
$res = true;
}
break;
case UPLOAD_ERR_NO_FILE: //未上传文件
$res = Comm_I18n::text('ajax.publicplatform.no_file');
break;
case UPLOAD_ERR_INI_SIZE: //文件大小超过 php.ini 中 upload_max_filesize 选项限定的值
case UPLOAD_ERR_FORM_SIZE: //文件大小超过 HTML 表单中 MAX_FILE_SIZE 选项限定的值
$res = Comm_I18n::text('ajax.publicplatform.more_than_max') . ini_get('upload_max_filesize');
break;
case UPLOAD_ERR_PARTIAL: //文件只有部分被上传
case UPLOAD_ERR_NO_TMP_DIR: //找不到临时文件夹
case UPLOAD_ERR_CANT_WRITE: //文件写入失败,PHP 5.1.0+
$res = Comm_I18n::text('ajax.riamsg.global.sysbusy');
break;
default :
$res = Comm_I18n::text('ajax.riamsg.global.sysbusy');
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment