function update($id, $data = array()) { check_allowed_category($id, END_RESPONSE == 'text'); if (!$data['update_time']) { $data['update_time'] = time(); } if (isset($data['url'])) { $data['url'] = $this->unique_url($data['url'], $id); } $re = parent::update($id, $data); if ($re && $data['url'] && defined('MAKE_HTML') && MAKE_HTML) { end_mkdir(END_ROOT . $data['url']); } return $re; }
<?php END_MODULE != 'admin' && die('Access Denied'); $action = $_GET['action']; $m = $_GET['m']; $file = $_FILES['upfile']; if (!is_dir(END_ROOT . END_UPLOAD_DIR)) { end_mkdir(END_ROOT . END_UPLOAD_DIR, 0777); } $err = true; //权限检查 if (!$_SESSION['login_user']['rights']['upload_add']) { die(LANG_ACCESS_DENIED); } if ($file['tmp_name']) { $myfile = $file["tmp_name"]; $ftype = getext($file['name']); if (!$ftype || !preg_match("/\\*\\.{$ftype};/i", $config['upload_file_types'])) { $err = true; $msg = lang('type_not_allowed'); } else { //$file_url = END_UPLOAD_DIR.basename($file['name']); $file_url = END_UPLOAD_DIR . date('m_d_H_i_s_') . rand(1111, 9999) . '.' . $ftype; if (@move_uploaded_file($myfile, END_ROOT . $file_url)) { $err = false; $msg = lang('success'); } else { $err = lang('failed'); } } if (strpos(',jpg,jpeg,gif,png,bmp', ',' . $ftype . ',') !== false) {
function end_upload_file($name, $file, $attr) { global $errors, $config; $ftype = getext($file['name']); //echo $ftype; //var_dump($config); var_dump($attr); die(); //如果是图片,那么只能上传这几种文件类型 if ($attr['type'] == 'image' || $attr['type'] == 'imagelist') { $attr['filetype'] = array('jpg', 'jpeg', 'png', 'gif'); } //验证文件类型 if (!$config['upload_file_types']) { $errors[$name] = lang('need_config_upload_file_types'); } else { if (!$attr['filetype']) { $errors[$name] = lang('file_type_not_configed'); } else { if (!preg_match("/\\*\\.{$ftype};/i", $config['upload_file_types']) && !in_array($ftype, $attr['filetype'])) { $errors[$name] = lang('not_allowed_file_type'); } else { $file_url = $file['name']; //如果文件名是一般的字母数字和-_,则不改变文件名 if (preg_match('/^[a-z0-9\\_\\-\\s\\.]+$/i', $file_url)) { $file_url = preg_replace('/\\s+/', '_', $file_url); } else { //否则改成时间和随机数 $file_url = date('Y_m_d_H_i_s_') . rand(1111, 9999) . '.' . $ftype; } if (!$file_url) { $errors[$name] = 'error'; } //保存到什么地方 if (!$attr['saveto']) { end_mkdir(END_ROOT . END_UPLOAD_DIR); $file_url = END_UPLOAD_DIR . $file_url; } else { end_mkdir(END_ROOT . $attr['saveto']); $file_url = $attr['saveto'] . $file_url; } //避免重名 while (file_exists(END_ROOT . $file_url)) { $file_url = dirname($file_url) . '/' . preg_replace('/\\.[a-z0-9]+$/i', '', basename($file_url)) . rand(1111, 9999) . '.' . $ftype; } //保存文件 if (@move_uploaded_file($file["tmp_name"], END_ROOT . $file_url)) { if ($attr['filter']) { $file_url = $attr['filter']($file_url); } //$data[$name] = $file_url; //更改图片尺寸 if ($attr['type'] == 'image' && is_array($attr['resize'])) { foreach ($attr['resize'] as $_r) { if (is_array($_r) && $_r['width'] && $_r['height']) { //调整图片尺寸,保存为 $__re = thumb($file_url, $_r['width'], $_r['height']); if ($_r['saveas']) { $data[$_r['saveas']] = $__re; } } } } if (($attr['type'] == 'image' || $attr['type'] == 'imagelist') && $attr['max_width']) { include_once END_ROOT . 'end_system/library/image.php'; $img = new Image(); $img->filepath = END_ROOT . $file_url; $img->resize_width($attr['max_width']); } } if (!file_exists(END_ROOT . $file_url)) { $errors[$name] = lang('upload_error'); } if (!is_writable(END_ROOT . dirname($file_url))) { $errors[$name] = dirname($file_url) . ' ' . lang('is not writable'); } return $file_url; } } } }