Home » Archives for 2013
Secure Image Upload with PHP
Security is an important thing for a php application. For this reason I tried to learn it. This case exist in the process of uploading a picture. To avoid undesirable I use the secure image are written by Mesut Timur. In addition I have also included an image filter .
Download Script
Example Usage:
HTML code:
PHP code:
Download Script
Example Usage:
HTML code:
<!DOCTYPE HTML> <head> <meta http-equiv="content-type" content="text/html" /> <meta name="author" content="Boomer" /> <title>Secure Image Upload</title> </head> <body> <form action="upload.php" method="post" enctype="multipart/form-data" > <input type="file" name="images" /> <input type="submit" value="Upload" /> </form> </body> </html>
PHP code:
<?php include 'inc/upload.php'; include 'inc/SecureImage.php' ; include 'inc/NudityFilter.class.php'; class Image_Upload { public $massage = ""; public $secure = true; public $nudity_filter = false; public $allowed_image = "jpg|png|jpeg|gif"; public $destination = ""; function upload( $parameter, $path ) { if( !class_exists( 'Secure_Upload')) { $this->massage = 'Upload Class not exists'; return false; } $upload = new Secure_Upload(); $proses = $upload->upload( $parameter , $path ); if( !$proses ) { $this->massage = $upload->massage; return false; } if( $this->secure && class_exists( 'SecureImage' )) { $image = new SecureImage($upload->file_destination); if( !$image->CheckIt()) { unlink( $upload->file_destination ); $this->massage = "Bad image"; return false; } } if( $this->nudity_filter && class_exists( 'NudityFilter' ) ) { $nfilter = new NudityFilter(); if( $nfilter->check( $upload->file_destination ) ) { $this->massage = "nude detected"; unlink( $upload->file_destination ); return false; } } $this->destination = $upload->destination; $this->massage = "Upload Sukses"; return true; } } $image = new Image_Upload(); $image->nudity_filter = true; $image->upload('images','images'); echo $image->massage; ?>
Simple PHP file cache
I try to share my experience
on write php code, in this time i will share simple php librarary for
caching content, this very simple. If you interesting you can get it
from my dropbox.