Login   Register  
PHP Classes
elePHPant
Icontem

File: ex_FileUpload.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ben Cooling  >  File-Upload  >  ex_FileUpload.php  >  Download  
File: ex_FileUpload.php
Role: Example script
Content type: text/plain
Description: Simple example usage of FileUpload class
Class: File-Upload
Validate and process uploaded files
Author: By
Last change: File added
Date: 2010-10-05 06:16
Size: 1,828 bytes
 

Contents

Class file image Download
<?php
ini_set
('display_errors''On'); 
error_reporting(E_ALL E_STRICT);

require_once(
'cl_FileUpload.php');

// Allow only PDF files and produce copies of files uploaded withthe same filename as exisiting files.
if (count($_FILES)>0){
    
$fileUpload = new FileUpload(array('naming'=>'random')); // All properties can be set on stand-alone lines or within an array when instantiating the FileUpload object
    
$fileUpload->file $_FILES['file']; 
    
$fileUpload->deny = array('pdf');
    if (
$fileUpload->upload_file()) echo 'File uploaded baby!';
    else echo 
$fileUpload->file['error'];
}

/*
// Allow all files, deny none by not setting either property. Also note the naming property has not been set when instantiating the object. Random filenames will be generated. 
if (count($_FILES)>0){
    $fileUpload = new FileUpload();
    $fileUpload->file = $_FILES['file'];
    $fileUpload->naming = 'random';
    if ($fileUpload->upload_file()) echo 'File uploaded baby!';
    else echo $fileUpload->file['error'];
}
*/

/*
// Deny PDF and ZIP files. As naming is not set, the default is unique. That means if a file is uploaded with the same filename as an exisiting file, an error will be returned
if (count($_FILES)>0){
    $fileUpload->file = $_FILES['file']; 
    $fileUpload->deny = array('pdf','zip');
    if ($fileUpload->upload_file()) echo 'File uploaded baby!';
    else echo $fileUpload->file['error'];
}
*/

?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>File class usage</title>
  </head>
  <body>
      <h1>Upload a zip file</h1>
    <form action="<?php echo $_SERVER['PHP_SELF'?>" method="post" enctype="multipart/form-data">
        <fieldset>
            <p><label>File 1:</label><input type="file" name="file" /></p>
            <p><button type="submit">Upload</button></p>
        </fieldset>
    </form>
    
  </body>
</html>