Skip to content

Instantly share code, notes, and snippets.

@k1ic
k1ic / query_string_to_array.php
Created January 30, 2015 06:01
将query_string转为数组
/**
* 将查询字符串解析为数组
* @param string
* @return array
*/
private static function _parseQueryString($query = '')
{
$res = array();
$pieces = explode('&', trim($query));
foreach ($pieces as $piece) // $piece likes 'serial=123'
@k1ic
k1ic / is_file_upload_succ.php
Created January 30, 2015 05:43
判断文件上传是否成功
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 {
@k1ic
k1ic / get_file_type.php
Created January 30, 2015 04:12
获取文件类型(通过读取文件前两个字节判断文件类型)
/**
* 获取文件类型(通过读取文件前两个字节判断文件类型)
* @param string $path 文件绝对路径
* @return string 文件扩展名
*/
public static function get_file_type ( $path = '' ) {
$res = '';
if ( file_exists($path) && is_readable($path) ) {
$fh = fopen($path, 'rb');
$bin = fread($fh, 2); //只读前两个字节