/** * 删除目录及目录下面的所有文件 * * @param string $dir 路径 * @return bool 如果成功则返回 TRUE,失败则返回 FALSE */ function dr_dir_delete($dir) { $dir = str_replace('\\', '/', $dir); if (substr($dir, -1) != '/') { $dir = $dir . '/'; } if (!is_dir($dir)) { return FALSE; } $list = glob($dir . '*'); foreach ($list as $v) { is_dir($v) ? dr_dir_delete($v) : @unlink($v); } return @rmdir($dir); }
/** * 上传头像处理 * 传入头像压缩包,解压到指定文件夹后删除非图片文件 */ public function upload() { if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) { exit(function_exists('iconv') ? iconv('UTF-8', 'GBK', '环境不支持') : 'The php does not support'); } // 创建图片存储文件夹 $dir = FCPATH . 'member/uploadfile/member/' . $this->uid . '/'; if (!file_exists($dir)) { mkdir($dir, 0777, true); } $filename = $dir . 'avatar.zip'; // 存储flashpost图片 file_put_contents($filename, $GLOBALS['HTTP_RAW_POST_DATA']); // 解压缩文件 $this->load->library('Pclzip'); $this->pclzip->PclFile($filename); $content = $this->pclzip->listContent(); if (!$content) { @unlink($filename); exit(function_exists('iconv') ? iconv('UTF-8', 'GBK', '文件已损坏') : 'The file has damaged'); } // 验证文件 foreach ($content as $t) { if (strpos($t['filename'], '..') !== FALSE || strpos($t['filename'], '/') !== FALSE || strpos($t['filename'], '.php') !== FALSE || strpos($t['stored_filename'], '..') !== FALSE || strpos($t['stored_filename'], '/') !== FALSE || strpos($t['stored_filename'], '.php') !== FALSE) { @unlink($filename); exit(function_exists('iconv') ? iconv('UTF-8', 'GBK', '非法名称的文件') : 'llegal name file'); } if (substr(strrchr($t['stored_filename'], '.'), 1) != 'jpg') { @unlink($filename); exit(function_exists('iconv') ? iconv('UTF-8', 'GBK', '文件格式校验不正确') : 'The document format verification is not correct'); } } // 解压文件 if ($this->pclzip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_REPLACE_NEWER) == 0) { @dr_dir_delete($dir); exit($this->pclzip->zip(true)); } @unlink($filename); if (!is_file($dir . '45x45.jpg') || !is_file($dir . '90x90.jpg')) { exit(function_exists('iconv') ? iconv('UTF-8', 'GBK', '文件创建失败') : 'File creation failure'); } // 上传头像积分处理 if (!$this->db->where('uid', $this->uid)->where('type', 0)->where('mark', 'avatar')->count_all_results('member_scorelog_' . $this->member['tableid'])) { $this->member_model->update_score(0, $this->uid, (int) $this->member_rule['avatar_experience'], 'avatar', "lang,m-057"); } // 上传头像虚拟币处理 if (!$this->db->where('uid', $this->uid)->where('type', 1)->where('mark', 'avatar')->count_all_results('member_scorelog_' . $this->member['tableid'])) { $this->member_model->update_score(1, $this->uid, (int) $this->member_rule['avatar_score'], 'avatar', "lang,m-057"); } // 更新头像 $this->db->where('uid', $this->uid)->update('member', array('avatar' => $this->uid)); exit('1'); }