PHP Classes

Secure Upload: Process uploaded files of multiple types

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 530 All time: 5,646 This week: 160Up
Version License PHP version Categories
secure-upload 1.0BSD License5HTTP, PHP 5, Files and Folders, Valid...
Description 

Author

This class can process uploaded files of multiple types.

It can check a given submitted file input values and verify if the file name extension is one the allowed for the expected file type. Currently it supports file types of image, audio or document.

For image file types it can check if the file is really an image of the supported types.

If the file size does not exceed the allowed limit or an image file does not exceed the allowed width and height, the class can move the file to the destination upload directory.

Picture of Taiwo Peace
  Performance   Level  
Name: Taiwo Peace is available for providing paid consulting. Contact Taiwo Peace .
Classes: 3 packages by
Country: Nigeria Nigeria
Age: 29
All time rank: 16506 in Nigeria Nigeria
Week rank: 405 Up13 in Nigeria Nigeria Down
Innovation award
Innovation award
Nominee: 1x

Example




<?php
//please do not forget to rate this class if it is usefull, and if you have any complaint or recommendation , please leave a comment at the forum session

require_once 'upload.php'; ?>
<!--make sure the enctype="multipart/form-data" is used in the form attributes -->
<form method="POST" action="<? echo $_SERVER['PHP_SELF'] ; ?>" enctype="multipart/form-data">
<input type="file" name="pic" />
<input type="submit" value="upload" />
</form>
<?php

$upload
=new upload();

//set the file type here ... available options $upload->filetype='image' or 'audio' or 'document' or 'any'
$upload->filetype='image';

// specify the input name here
$upload->inputname='pic';

//specify the upload path
$upload->uploadpath='upload/';
//set allowed size in kilobyte , 1024kb make 1megabyte
$upload->allowedsize=100000;

//if there is no restriction in the dimension of image or if document type is not image , there is no need to including $upload->height=120; and $upload->width=120; in your code
//set image height in pixel ,
$upload->height=120;
//set image width in pixel ,
$upload->width=120;

//check if upload is successfull
if($upload->upload()==false){
//eco the reasin for the error
echo $upload->error;
}

else{

//echo the imagename, this name can be inserted into a database for referencing
echo $imgname=$upload->imgname;
}
?>


  Files folder image Files  
File Role Description
Accessible without login Plain text file test.php Example Example Usage
Plain text file upload.php Class Main Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:530
This week:0
All time:5,646
This week:160Up
 User Ratings  
 
 All time
Utility:87%StarStarStarStarStar
Consistency:62%StarStarStarStar
Documentation:-
Examples:81%StarStarStarStarStar
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1520