hiokwee/filemanager

dev-master 2017-06-18 12:26 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:36:43 UTC


README

方法

  1. 文件 (string $_target_dir)
    $_target_dir    文件保存的目标目录

  2. upload (string $param_name) : boolean
    $param_name    HTML表单输入字段名称

  3. delFileByName (string $name) : boolean
    $name    文件名

  4. getFileByName (string $name) : boolean
    $name    文件名

  5. getFileList () : string

  6. getTargetFolder () : string

  7. setAllowedExtensions (array<mixed,string> $extensions)
    $extensions    允许的扩展类型

  8. setOnlyAllowImage (boolean $image_only)
    $image_only    仅允许图片文件类型

  9. setMaxFileSize (integer $max_file_size)
    $max_file_size    允许的最大文件大小(字节)

  10. setScanFile (boolean $scan_file)
    $scan_file    启用病毒文件扫描


示例

$fm = new File("uploads/");
$fm->setAllowedExtensions(["PNG", "GIF", "TXT"]);
$fm->setOnlyAllowImage(true);
$fm->setMaxFileSize(5120);
$fm->setScanFile(true);

if (isset($_POST["act"])) {

        // upload file
        if ($_POST["act"] === "upload") {
                try {
                        $fm->upload("fileToUpload");
                }
                catch (Exception $e) {
                }
        }
        
        // download file by name
        elseif ($_POST["act"] === "download") {
                if (isset($_POST["filename"])) {
                        try {
                                $fm->getFileByName($_POST["filename"]);
                        }
                        catch (Exception $e) {
                        }
                }
        }
        
        // delete file by name
        elseif ($_POST["act"] === "delete") {
                if (isset($_POST["filename"])) {
                        try {
                                $fm->delFileByName($_POST["filename"]);
                        }
                        catch (Exception $e) {
                        }
                }
        }
}