function fileupload() { $json =& loader::lib('json'); $error = ""; $msg = ""; if (!$this->user->loggedin()) { echo $json->encode(array('error' => lang('not_authorized'), 'msg' => '')); exit; } $upaction = $this->getPost('upaction'); if ($upaction == 'watermark') { $path_dir = 'data/watermark'; $file_type = array('png', 'jpg', 'gif'); } elseif ($upaction == 'logo') { $path_dir = 'data/logo'; $file_type = array('png', 'jpg', 'gif'); } $fileElementName = 'fileToUpload'; if (!empty($_FILES[$fileElementName]['error'])) { $error = lang('upload_error'); } elseif (empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none') { $error = lang('need_sel_upload_file'); } else { $filename = $_FILES[$fileElementName]['name']; $fileext = file_ext($filename); $filesize = $_FILES[$fileElementName]['size']; $allowsize = allowsize($this->setting->get_conf('upload.allow_size')); if (!in_array($fileext, $file_type)) { echo $json->encode(array('error' => lang('failed_not_support', $filename), 'msg' => '')); exit; } if ($allowsize && $filesize > $allowsize) { echo $json->encode(array('error' => lang('failed_larger_than_usetting', $filename), 'msg' => '')); exit; } if ($filesize == 0) { echo $json->encode(array('error' => lang('failed_if_file', $filename), 'msg' => '')); exit; } $storlib =& loader::lib('storage'); $path = $path_dir . '/' . date('Ymd') . '.' . $fileext; if ($storlib->upload($path, $_FILES[$fileElementName]['tmp_name'])) { $msg = $path; } else { $error = lang('upload_error'); } } echo $json->encode(array('error' => $error, 'msg' => $msg)); exit; }
function save() { @set_time_limit(0); @ignore_user_abort(true); $type = $this->getGet('t'); $album_id = intval($this->getRequest('aid')); if (!$album_id) { showError(lang('pls_sel_album')); } if ($type == 'multi') { need_login('ajax'); /*$files_count = intval($this->getPost('muilti_uploader_count')); for($i=0;$i<$files_count;$i++){ $filename = $this->getPost("muilti_uploader_{$i}_tmpname"); $realname = $this->getPost("muilti_uploader_{$i}_name"); $purename = file_pure_name($filename); $purerealname = file_pure_name($realname); $photorow = $this->mdl_photo->get_photo_by_name_aid($album_id,$purename); if($photorow){ $this->mdl_photo->update($photorow['id'],array('name'=>$purerealname)); } } */ $this->mdl_album->update_photos_num($album_id); $this->mdl_album->check_repare_cover($album_id); $gourl = site_link('photos', 'index', array('aid' => $album_id)); form_ajax_success('box', lang('upload_photo_success'), null, 1, $gourl); } else { need_login('page'); $this->output->set('album_id', $album_id); $album_info = $this->mdl_album->get_info($album_id); $this->output->set('album_info', $album_info); $page_title = lang('upload_photo') . ' - ' . $this->setting->get_conf('site.title'); $page_keywords = $this->setting->get_conf('site.keywords'); $page_description = $this->setting->get_conf('site.description'); $this->page_init($page_title, $page_keywords, $page_description); $imglib =& loader::lib('image'); $supportType = $imglib->supportType(); $empty_num = 0; $error = ''; $allowsize = allowsize($this->setting->get_conf('upload.allow_size')); if (isset($_FILES['imgs'])) { foreach ($_FILES['imgs']['name'] as $k => $upfile) { if (!empty($upfile)) { $filesize = $_FILES['imgs']['size'][$k]; $tmpfile = $_FILES['imgs']['tmp_name'][$k]; $filename = $upfile; $fileext = file_ext($filename); if ($_FILES['imgs']['error'][$k] == 1) { $error .= lang('failed_larger_than_server', $filename) . '<br />'; continue; } if ($allowsize && $filesize > $allowsize) { $error .= lang('failed_larger_than_usetting', $filename) . '<br />'; continue; } if ($filesize == 0) { $error .= lang('failed_if_file', $filename) . '<br />'; continue; } if (!in_array($fileext, $supportType)) { $error .= lang('failed_not_support', $filename) . '<br />'; continue; } if (!$this->mdl_photo->save_upload($album_id, $tmpfile, $filename, true, array('cate_id' => $album_info['cate_id']))) { $error .= lang('file_upload_failed', $filename) . '<br />'; } } else { $empty_num++; } } } else { $error = lang('need_sel_upload_file'); } if (isset($_FILES['imgs']) && $empty_num == count($_FILES['imgs']['name'])) { $this->output->set('msginfo', '<div class="failed">' . lang('need_sel_upload_file') . '</div>'); } else { $this->mdl_album->update_photos_num($album_id); $this->mdl_album->check_repare_cover($album_id); if ($error) { $this->output->set('msginfo', '<div class="failed">' . $error . '</div>'); } else { $this->output->set('msginfo', '<div class="success">' . lang('upload_photo_success') . '<a href="' . site_link('photos', 'index', array('aid' => $album_id)) . '">' . lang('view_album') . '</a></div>'); } } $crumb_nav = array(); $crumb_nav[] = array('name' => lang('upload_photo')); $this->page_crumb($crumb_nav); loader::view('upload/normal'); } }