function save($folder, $name) { if (!dir($folder)) { folder::create($folder); } else { folder::publico($folder); } $this->savePath = $folder . $name . "." . $this->mime; }
static function upload($fileName, $destination) { if (isset($_FILES[$fileName])) { folder::create(dirname($destination)); if (move_uploaded_file($_FILES[$fileName]['tmp_name'], $destination)) { PHPToolkit::getClass('FileInterface'); return new FileInterface($destination); } } return false; }
/** * 创建文件夹,返回true或者false */ public static function create($dir, $mode = 0755) { $dir = path::decode($dir); if (is_dir($dir) || @mkdir($dir, $mode)) { return true; } if (!folder::create(dirname($dir), $mode)) { return false; } return @mkdir($dir, $mode); }
/** * 写入文件 * * @param string $file * @param string $content * @param boolean $overwrite * @return boolean */ public static function write($file, $content = '', $overwrite = TRUE) { $file = path::decode($file); //当目录不存在的情况下先创建目录 if (!folder::exists(dirname($file))) { folder::create(dirname($file)); } if (!file::exists($file) || $overwrite) { return @file_put_contents($file, $content); } return false; }
public function savefile($savepath, $filename) { //返回实际目录 $dir = ZOTOP_PATH_ROOT . DS . $savepath; //目录检测 if (!is_dir($dir) && !folder::create($dir, 0777)) { $this->error = 8; //目录不存在且无法自动创建 return false; } @chmod($dir, 0777); if (!is_writeable($dir) && $dir != '/') { $this->error = 9; //不可写 return false; } $savefile = $dir . $filename; return $savefile; }
/** * 上传文件 * * @param string $name FILE字段名称 * @param string $path 上传的路径 * @param string $ext 扩展名 * @param boolean $rename 是否重新命名 * @return array */ public static function upload($name, $path, $ext, $rename = true) { if (!file_exists(dirname($path))) { folder::create(dirname($path)); } $ext = explode(',', $ext); $files = $_FILES[$name]; $attachments = array(); //转换数组 if (is_array($files['name'])) { foreach ($files as $key => $var) { foreach ($var as $id => $val) { $attachments[$id][$key] = $val; } } } else { $attachments[] = $files; } //上传 $return = array(); foreach ($attachments as $k => $file) { if (in_array(self::ext($file['name']), $ext)) { $tmp = $path; if ($rename) { $tmp .= DS . rand::string(10) . self::ext($file['name']); } else { $tmp .= DS . $file['name']; } @move_uploaded_file($file['name'], $tmp); $return[] = $tmp; @unlink($file['tmp_name']); } else { $return[] = false; } } return $return; }
require_once "../../includes/initialize.php"; $session->parent_folder_id = $_SESSION['parent_folder_id']; if (isset($_POST['submit'])) { $foldername = trim($_POST['foldername']); $username = $session->username; $parent_folder_id = $session->parent_folder_id; $new_folder = folder::check_existing_folder($foldername, $parent_folder_id, $username); if ($new_folder) { $session->message("Folder is already created"); redirect_to("list_files.php"); } else { $folder = new folder(); $folder->foldername = $foldername; $folder->username = $session->username; $folder->parent_folder_id = $_SESSION['parent_folder_id']; if ($folder->create()) { $created_folder = folder::return_folder_id($folder->foldername, $folder->username, $folder->parent_folder_id); //$new_parent_folder = $created_folder->folder_id; $new_folder_name = $created_folder->foldername; $session->message(" {$new_folder_name} is created"); redirect_to("list_files.php?parent_folder_id={$parent_folder_id}"); } } } else { $foldername = ""; } include_layout_template('admin_header.php'); echo output_message($message); ?> <div id='left-box' class='child'> <ul id ="list_types_sort">