PHP Classes

File: document.php

Recommend this page to a friend!
  Classes of alismith   PHP Files Class   document.php   Download  
File: document.php
Role: Example script
Content type: text/plain
Description: Example
Class: PHP Files Class
Manage uploaded files and serve them for download
Author: By
Last change:
Date: 4 years ago
Size: 1,878 bytes
 

Contents

Class file image Download
Class usages :
define("DEFAULT_LANGUAGE","EN");
define("BASE_UPLOAD_DIR","files/");


include('files.php');


/* Save Image and resize to 120*120 and convert to jpg */
if(isset($_FILES['file']) && !empty($_FILES['file'])){

$validation = ["file"=>"mime=png|max-size=300000|multiple=true"];
$options = ["convert" => "jpg", "resize" => "120*120", "overwrite" => true];

$file = new \Utilities\File\Files('file',$validation);
$result = $file->store('/',false,$options);

echo '<pre>';
print_r($result);

}



/* Move Destination Image (not include BASE_UPLOAD_DIR) */

if(array_key_exists('file',$result['success'])){
    $localfile = "files/".$result['success']['file'][0];
    $file = new \Utilities\File\Files();
    if($file->load($localfile)->moveTo('moved_file/')){
        echo "<br/>\n File successfully moved!";
    }else{
        echo "<br/>\n File transfer failed!";
    }
}


/* More Example : */
$file = new \Utilities\File\Files('profile');
$profile_image = $file->get(); // get() OR first()
if($profile_image->ext() == 'jpg'){
$file = new \Utilities\File\Files($profile_image);
$save = $file->store('images/profile',$profile_image->originalName());
}
Example 2 :
function files($file=false,$validation=false){
 
    return new \Utilities\File\Files($file,$validation);
  }

$save = files('profile')->store('/images/profile','myimg');



/* Validation Rules */

multiple
type
mime
size
min-size
max-size
width
height

Example : ['slider'=>'multiple=true|mime=jpg,jpeg|max-size=1000000']



/* Download Local File */

$file = new \Utilities\File\Files();
$file->load('path/to/file/document.docx')->download();

Example 2 : (stream download)
$file = new \Utilities\File\Files();
$file->load('path/to/file/document.docx')->download(true); //send file as stream to browser