Wallogit.com
2017 © Pedro Peláez
methods
File (string $_target_dir)
*$_target_dir* The target directory where the files will be saved, (*1)
upload (string $param_name) : boolean
$param_name The HTML form input field name, (*2)
delFileByName (string $name) : boolean
$name Name of the file, (*3)
getFileByName (string $name) : boolean
$name Name of the file, (*4)
getFileList () : string
, (*5)
getTargetFolder () : string
, (*6)
setAllowedExtensions (array<mixed,string> $extensions)
$extensions The permitted extension types, (*7)
setOnlyAllowImage (boolean $image_only)
$image_only Permit only image file types, (*8)
setMaxFileSize (integer $max_file_size)
$max_file_size Maximum permitted file size in bytes, (*9)
setScanFile (boolean $scan_file)
$scan_file Enable anti-virus file scan
, (*10)
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) {
}
}
}
}