本文整理汇总了PHP中tool::fileext方法的典型用法代码示例。如果您正苦于以下问题:PHP tool::fileext方法的具体用法?PHP tool::fileext怎么用?PHP tool::fileext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tool
的用法示例。
在下文中一共展示了tool::fileext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: logo_upload
/**
* 上传新Logo
*/
public function logo_upload()
{
$return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented');
if ($_POST) {
if (!isset($_FILES["img_val"]) || !is_uploaded_file($_FILES["img_val"]["tmp_name"]) || $_FILES["img_val"]["error"] != 0) {
remind::set(Kohana::lang('o_global.illegal_data'), 'site/config');
}
$site = Mysite::instance($this->site_id)->get();
//Logo文件名
$filename = $_FILES['img_val']['name'];
$file_ext = tool::fileext($filename);
//资源文件最大大小(default:1M)
$file_max_size = kohana::config('theme.file_max_size');
$file_max_size = $file_max_size > 0 ? $file_max_size : 1048576;
$type = array('gif', 'png', 'jpg', 'jpeg');
//判断文件类型
if (!in_array(strtolower($file_ext), $type)) {
remind::set(Kohana::lang('o_site.file_type_error'), 'site/config');
}
$val = $_FILES['img_val']['name'];
$file_size = filesize($_FILES['img_val']['tmp_name']);
if ($file_size > $file_max_size) {
remind::set(Kohana::lang('o_site.pic_size_out_range'), 'site/config');
}
//$filename = 'logo.' . $file_ext;
//$file = file_get_contents($_FILES['img_val']["tmp_name"]);
//Storage_server::instance()->cache_site($site['id'],$filename,$file);
$AttService = AttService::get_instance($this->img_dir_name);
$AttService->default_img_type = 'gif';
$img_id = $AttService->save_default_img($_FILES['img_val']["tmp_name"], 'logo');
if (!$img_id) {
remind::set(Kohana::lang('o_product.phprpc_pic_save_failed'), 'site/config');
}
//更新数据库标识
$data = Mysite::instance()->get();
$data['logo'] = $AttService->get_img_url($img_id, 0, 0);
$data['logo_desc'] = $this->input->post('logo_desc');
if (Mysite::instance()->update_site_config($data)) {
remind::set(Kohana::lang('o_site.logo_success_upload'), 'site/config', 'success');
} else {
remind::set(Kohana::lang('o_site.logo_error_upload'), 'site/config');
}
}
if (request::is_ajax()) {
$site = Mysite::instance()->get();
//VIEW
$return_template = $this->template = new View('template_blank');
$this->template->content = new View('site/config_logo_upload');
$this->template->content->data = $site;
$return_str = $return_template->render();
$return_struct['status'] = 1;
$return_struct['code'] = 200;
$return_struct['msg'] = 'Success';
$return_struct['content'] = $return_str;
exit(json_encode($return_struct));
} else {
$return_struct['code'] = 400;
$return_struct['msg'] = Kohana::lang('o_global.access_denied');
exit(json_encode($return_struct));
}
}
示例2: upload_attach
public function upload_attach($name, $dirname, $type = 'pic')
{
$return = array('code' => 0, 'msg' => '');
if ($_FILES) {
//var_dump($_FILES);die();
$file_input = $name;
if (!isset($_FILES[$file_input]) || !is_uploaded_file($_FILES[$file_input]["tmp_name"]) || $_FILES[$file_input]["error"] != 0) {
$return['msg'] = '上传文件出错';
//echo json_encode($return);
return $return;
}
$file_obj = $_FILES[$file_input];
$filename = $file_obj['name'];
$file_ext = strtolower(tool::fileext($filename));
if ($type == 'pic') {
$type = kohana::config('upload.pic_file_ext');
$file_max_size = kohana::config('upload.pic_max_size');
} else {
$type = kohana::config('upload.model_file_ext');
$file_max_size = kohana::config('upload.file_max_size');
}
if (!in_array($file_ext, $type)) {
$return['msg'] = '文件格式错误';
//echo json_encode($return);
return $return;
}
$file_size = filesize($file_obj['tmp_name']);
if ($file_size > $file_max_size) {
$return['msg'] = '文件太大';
//echo json_encode($return);
return $return;
}
$AttService = AttService::get_instance($dirname);
if ($type == 'pic') {
$r = $AttService->save_default_img($file_obj["tmp_name"]);
if ($r == FALSE) {
$return['msg'] = '上传出错';
//echo json_encode($return);
return $return;
}
} else {
$r = $AttService->save_default_file($file_obj["tmp_name"], $file_ext);
if ($r == FALSE) {
$return['msg'] = '上传出错';
//echo json_encode($return);
return $return;
}
}
$img_info = array('name' => $filename, 'path' => $dirname . '/' . $r);
$return['code'] = 1;
$return['data'] = $img_info;
//echo json_encode($return);
return $return;
}
}
示例3: logo_upload
/**
* 上传新Logo
*/
public function logo_upload()
{
$return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented');
if ($_POST) {
if (!isset($_FILES["img_val"]) || !is_uploaded_file($_FILES["img_val"]["tmp_name"]) || $_FILES["img_val"]["error"] != 0) {
remind::set(Kohana::lang('o_global.illegal_data'), 'site/news/logo_upload');
}
$filename = $_FILES['img_val']['name'];
$file_ext = tool::fileext($filename);
//资源文件最大大小(default:1M)
$file_max_size = kohana::config('theme.file_max_size');
$file_max_size = $file_max_size > 0 ? $file_max_size : 1048576;
$type = array('gif', 'png', 'jpg', 'jpeg');
//判断文件类型
if (!in_array(strtolower($file_ext), $type)) {
remind::set(Kohana::lang('o_site.file_type_error'), 'site/news/logo_upload');
}
$val = $_FILES['img_val']['name'];
$file_size = filesize($_FILES['img_val']['tmp_name']);
if ($file_size > $file_max_size) {
remind::set(Kohana::lang('o_site.pic_size_out_range'), 'site/news/logo_upload');
}
//$filename = 'logo.' . $file_ext;
//$file = file_get_contents($_FILES['img_val']["tmp_name"]);
//Storage_server::instance()->cache_site($site['id'],$filename,$file);
$AttService = AttService::get_instance($this->img_dir_name);
$AttService->default_img_type = 'gif';
$img_id = $AttService->save_default_img($_FILES['img_val']["tmp_name"], date("YmdHis", time()));
if (!$img_id) {
remind::set(Kohana::lang('o_product.phprpc_pic_save_failed'), 'site/news');
}
echo "<script>\n";
echo "if (parent.document.add_form.newpic != undefined){\n";
echo "\tparent.document.add_form.newpic.value='" . $AttService->get_img_url($img_id, 0, 0) . "';\n";
echo "} else if (parent.document.getElementById('newpic') != undefined){\n";
echo "\tparent.document.getElementById('newpic').value='" . $AttService->get_img_url($img_id, 0, 0) . "';\n";
echo "}";
echo "window.parent.\$(\"#upload_content\").dialog(\"close\");";
echo "</script>\n";
d($AttService->get_img_url($img_id, 0, 0));
}
$this->template->content = new View("site/news_logo_upload");
}