PHP Classes

File: example/validation_files.php

Recommend this page to a friend!
  Classes of Everton da Rosa  >  PTK Validation  >  example/validation_files.php  >  Download  
File: example/validation_files.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PTK Validation
Validate values of dates, files and directories
Author: By
Last change: Backup
Date: 7 years ago
Size: 2,390 bytes
 

Contents

Class file image Download
<?php

/*
 * Copyright (C) 2014 Everton
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This file is a simple example of use Ptk\utils\Validator for testing an validate files.
 */

function show_validation($file, $rules){
    global
$onerror;
    if(\
Ptk\utils\Validator::file($file, $rules, true)){
        echo
"This file $file is VALID.".PHP_EOL;
    }else{
        echo
"This file $file is INVALID.".PHP_EOL;
        echo
"Invalid for: ".PHP_EOL;
       
        echo
join(', ', $onerror);
    }
}

try{
    require
'examples.inc.php';
   
   
//testing files
   
$file = './example.db';
   
$rules = array(
       
'dir' => array(__DIR__)//Checks if the file is in one of these directories.
       
,'perm' => '0666'//Check the file permissions.
       
,'min' => 1024//Checks if the file has a minimum size in bytes.
       
,'max' => 1024 * 10//Checks if the file has a maximum size in bytes.
       
,'type' => array('file', 'char', 'link')//Checks the type of the file.
       
,'match' => '*.db'//Compares with a filename pattern.
       
,'exec' => false//Checks if the file is executable.
       
,'link' => false//Checks if the file is a symbolic link
       
,'read' => true//Checks whether the file can be read.
       
,'upload' => false//Checks if the file was uploaded via HTTP POST.
       
,'write' => true//Checks whether the file can be write.
       
,'ext' => array('db')//Checks if the file has one of the allowed extensions.
       
,'mimetype' => array('application/octet-stream')//Check the mime-type of file
       
,'mimeencode' => array('binary')//Check the mime-encode of file
   
);
   
show_validation($file, $rules);
   
} catch (
Exception $ex) {
    echo
$ex->getMessage();
   
//echo $ex->getTraceAsString();
   
exit($ex->getCode());
}

For more information send a message to info at phpclasses dot org.