public function preform() { $uploadFile = new FileUpload(); $uploadFile->set("path", "./images/"); $uploadFile->set("maxsize", 2000000); $uploadFile->set("allowtype", array("gif", "png", "jpg", "jpeg")); $uploadFile->set("israndname", false); }
public function preform() { $uploadFile = new FileUpload(); $uploadFile->set("maxsize", 2000000); $uploadFile->set("allowtype", array("gif", "png", "jpg", "jpeg")); $uploadFile->set("israndname", true); if ($this->params['safe']['type'] == "addArticle") { $path = "../uploadfile/article/" . $this->params['safe']['fenlei_id'] . "/"; $uploadFile->set("path", $path); if ($uploadFile->upload('fm_img')) { $data = array('uid' => 1, 'title' => $this->params['safe']['title'], 'contents' => $this->params['safe']['contents'], 'fenlei_id' => $this->params['safe']['fenlei_id'], 'fm_img' => $path . $uploadFile->getFileName(), 'time' => time()); $DaoArticle = new DaoArticle(); $DaoArticle->insertArticle($data); } else { //获取上传失败以后的错误提示 throw new Exception('error_file_upload', $uploadFile->getErrorMsg()); } } elseif ($this->params['safe']['type'] == "addUser") { $path = "../uploadfile/user_img/" . $this->params['safe']['user_name'] . "/"; $uploadFile->set("path", $path); if ($uploadFile->upload('user_img')) { $data = array('user_name' => $this->params['safe']['user_name'], 'user_nickname' => $this->params['safe']['user_nickname'], 'user_password' => md5($this->params['safe']['password']), 'user_qm' => "这家伙还没写签名呢!", 'user_img' => $path . $uploadFile->getFileName(), 'user_inTime' => time()); $DaoUser = new DaoUser(); $DaoUser->addUser($data); } else { //获取上传失败以后的错误提示 throw new Exception('error_file_upload', $uploadFile->getErrorMsg()); } } elseif ($this->params['safe']['type'] == "addfenlei") { $path = "../uploadfile/Fenlei/"; $uploadFile->set("path", $path); if ($uploadFile->upload('fenlei_img')) { $data = array('name' => $this->params['safe']['name'], 'time' => time(), 'fenlei_img' => $path . $uploadFile->getFileName()); $DaoFenlei = new DaoFenlei(); $DaoFenlei->addFenlei($data); } } }
include $_SERVER['DOCUMENT_ROOT'] . $folder_name . '/config.inc.php'; //引入文件操作类 require '../public/FileUtil.php'; //引入文件上传类 require '../public/fileUpload.class.php'; function createFile($title, $type, $content) { //生成文件 $File = new FileUtil(); $File->writetofile(BASE_PATH . 'upload/webstyle/public/' . $type . '/' . $title . '.' . $type, $content); return $codeFilePath = '/manage/upload/webstyle/public/' . $type . '/' . $title . '.' . $type; } if (isset($_POST['category']) && $_POST['category'] == 'code') { $up = new FileUpload(); //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成) $up->set("path", "../../upload/webstyle/public/" . $_POST['code_type']); $up->set("maxsize", 2000000); $up->set("allowtype", array("gif", "png", "jpg", "jpeg", 'css', 'js')); $up->set("israndname", false); //使用对象中的upload方法, 就可以上传文件, 方法需要传一个上传表单的名子 pic, 如果成功返回true, 失败返回false if ($up->upload("file")) { var_dump($up->getFileName()); $file_path_code = '/manage/upload/webstyle/public/' . $_POST['code_type'] . '/' . $up->getFileName(); } else { echo '<pre>'; //获取上传失败以后的错误提示 var_dump($up->getErrorMsg()); echo '</pre>'; } $db = new DB(); $data['id'] = "";
function upload($path = '') { $path = trim($path, '/'); $folder = $this->BasePath . $path; if (!is_dir($folder)) { if (is_gb2312($path)) { $path = iconv('gb2312', 'utf-8', $path); } throw new Exception("文件夹 '{$path}' 不存在。"); } if (!file_exists('fileupload.class.php')) { throw new Exception("没找到文件'fileupload.class.php, 无法上传文件。"); } require_once 'fileupload.class.php'; $up = new FileUpload(); //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成) $up->set("path", $folder); $up->set("maxsize", 8 * 1024 * 1024); if (empty($this->allowType) || $this->allowType == '*') { $up->set("allowtype", explode(',', $this->allType)); } else { $up->set("allowtype", explode(',', $this->allowType)); } $up->set("israndname", false); if (!$up->upload("file")) { $errors = $up->getErrorMsg(); if (is_array($errors)) { $errors = implode("\n", $errors); } throw new Exception($errors); } else { $filenames = $up->getFileName(); if (is_string($filenames)) { $filenames[] = $filenames; } foreach ($filenames as $key => $value) { $filename = iconv('utf-8', 'gb2312', $value); if (true === @rename($folder . '/' . $value, $folder . '/' . $filename)) { $filenames[$key] = $filename; } } } return $up->getFileName(); }
function upload($path = '') { $path = $this->BaseUrl . '/' . trim($path, '/'); if (!is_dir($path)) { $data['error'] = 'Folder ' . $path . ' does not exist.'; return $data; } $up = new FileUpload(); //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成) $up->set("path", $path); $up->set("maxsize", 8 * 1024 * 1024); if (!empty($this->allowType) && $this->allowType != '*') { $up->set("allowtype", explode(',', $this->allowType)); } $up->set("israndname", false); if ($up->upload("upfile")) { return $up->getFileName(); } else { $data['error'] = $up->getErrorMsg(); } /**/ return $data; }