hiokwee/filemanager

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

This package is not auto-updated.

Last update: 2024-04-28 02:11:11 UTC


README

methods

  1. File (string $_target_dir)
    $_target_dir    The target directory where the files will be saved

  2. upload (string $param_name) : boolean
    $param_name    The HTML form input field name

  3. delFileByName (string $name) : boolean
    $name    Name of the file

  4. getFileByName (string $name) : boolean
    $name    Name of the file

  5. getFileList () : string

  6. getTargetFolder () : string

  7. setAllowedExtensions (array<mixed,string> $extensions)
    $extensions    The permitted extension types

  8. setOnlyAllowImage (boolean $image_only)
    $image_only    Permit only image file types

  9. setMaxFileSize (integer $max_file_size)
    $max_file_size    Maximum permitted file size in bytes

  10. setScanFile (boolean $scan_file)
    $scan_file    Enable anti-virus file scan


example

$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) {
                        }
                }
        }
}