PHP Classes

Simple upload class: Validate and process an uploaded file

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 68%Total: 388 All time: 6,674 This week: 61Up
Version License PHP version Categories
uploadclass 1.0.0Freely Distributable5HTTP, PHP 5, Files and Folders
Description 

Author

This package can validate and process an uploaded file.

It can take an array of values of an uploaded file and validate if it has been correctly uploaded, the allowed file name extensions and the size does not exceed a given limit.

Validated uploaded files are moved to a given destination directory.

Picture of Ngilio
  Performance   Level  

 

Example


<?php
   
if(isset($_POST["Send"])){ // If form is submited
       
require_once("uploadClass.php");
       
$file=$_FILES["fileField"]; // Get file from form
       
       
$destination="Uploaded_Files/";
        if (!
file_exists($destination)) { // If 'destination' folder dosn't exist, create
           
mkdir($destination);
        }

       
$process=new Upload($destination); // Set 'destination' as new default destination folder for upload
       
       
$uploadResult=$process->executeUpload($file); // Attach file to upload process
       
       
echo $uploadResult;
    }
?>

<form action="?" method="POST" enctype="multipart/form-data">
    <table id="dyntable" class="table table-bordered">
        <tr>
            <td>
                File
            </td>
            <td>
                <input type="file" name="fileField" id="fileField" placeholder="">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <button type="submit" name="Send">Send</button>
                    <button type="reset">Reinitialiser</button>
                </center>
            </td>
        </tr>
    </table>
</form>


Details

# INTRODUCTION # The **uploadclass** package is a class designed to simplified upload process # EXAMPLE # To use this class, you just need to see example file. In fact, you just have to do something like : <?php if(isset($_POST["Send"])){ // If form is submited require_once("uploadClass.php"); // Load uploadClass file once $file=$_FILES["fileField"]; // Get file from form $destination="Uploaded_Files/"; if (!file_exists($destination)) { // If 'destination' folder dosn't exist, create mkdir($destination); } $process=new Upload($destination); // Set 'destination' as new default destination folder for upload $uploadResult=$process->executeUpload($file); // Attach file to upload process echo $uploadResult; } ?> <form action="?" method="POST" enctype="multipart/form-data"> <table id="dyntable" class="table table-bordered"> <tr> <td> File </td> <td> <input type="file" name="fileField" id="fileField" placeholder=""> </td> </tr> <tr> <td colspan="2"> <center> <button type="submit" name="Send">Send</button> <button type="reset">Reinitialiser</button> </center> </td> </tr> </table> </form> # REFERENCE # ## public function setParameters($dest=null,$types=null) ## Set new destination (dest) and authorized file extensions list (types) ## public function executeUpload($uploaded_file,$destination=null) Get file and execute upload

  Files folder image Files (3)  
File Role Description
Accessible without login Plain text file example.php Example Show how to use uploadclass
Accessible without login Plain text file readme Doc. Readme file
Plain text file uploadClass.php Class Full class description

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:388
This week:0
All time:6,674
This week:61Up
User Ratings User Comments (1)
 All time
Utility:87%StarStarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:87%StarStarStarStarStar
Examples:81%StarStarStarStarStar
Tests:-
Videos:-
Overall:68%StarStarStarStar
Rank:377
 
Very simple and secure way to upload images.
8 years ago (Terry Woody)
80%StarStarStarStarStar