Login   Register  
PHP Classes
elePHPant
Icontem

File: image_upload.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Anirban Nath  >  Secure Image Uploading and Resizing  >  image_upload.php  >  Download  
File: image_upload.php
Role: Example script
Content type: text/plain
Description: main file for uploading images, ie index file whre user can view the uploading gui
Class: Secure Image Uploading and Resizing
Validate and resize uploaded image files
Author: By
Last change:
Date: 2011-03-07 21:55
Size: 2,457 bytes
 

Contents

Class file image Download
<?php 
require_once 'class_secure_resize_storing_images.php';

require(
'conn.php'); /*important, change in conn.php to your settings*/

?>
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)  /*******CHECKING FILE IS UPLOADED AND UPLOAD BUTTON IS CLICKED OR  ACTIVE*********/
{

$img = new secureimage();

$type=$_FILES['userfile']['type'];
$size=$_FILES['userfile']['size'];
$error=$_FILES['userfile']['error'];
$name=$_FILES['userfile']['tmp_name'];
$realname=$_FILES['userfile']['name'];
$status=$img->checkfile($size,$error$name);
if (!
$status) {
echo 
$status;
//die();

 
}else{ 


$TABLE="CREATE TABLE IF NOT EXISTS `upload` 
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(30) NOT NULL,
 `type` varchar(30) NOT NULL,
 `size` int(11) NOT NULL,
 `content` longblob NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=132 DEFAULT CHARSET=latin1"
/******* THIS WILL CREATE A TABLE NAME UPLOAD IN YOUR DATABASE, OR YOU CAN CRETAE YOUR OWN ******/

mysql_query($TABLE);

$image=$img-> fileoperation($_FILES['userfile']['tmp_name']);

$sizereduced=$img->redsize;                                      /*** GETTING THE IMAGE REDUCED SIZE FROM CLASS SECUREIMAGE***/

$query "INSERT INTO upload (name, type, size, content ) ".
"VALUES ('$realname', '$type',  '$sizereduced', '$image')";
//echo $query;                                                            /** FOR DEBUGGING***/

$result=mysql_query($query) or die('Error, query failed'.mysql_error()); 
if ( 
$result  ){

 
?> <a href="display_images.php">Yippeei ...... sucessfully uploaded  !!! click here to check  it out </a>
 <?php }
 else {  echo 
" Ooops ...seems some errors in uploading!! ";}
}}
?>

<html>
<title> IMAGE UPLOADING( SECURE, RESIZE, AND STORING IN MYSQL) BY An!rban from "INDIA" </title>
<body>
<div style="position:relative; padding-left:280PX; padding-top:150PX; -moz-border-radius:10px;">
<form method="post" enctype="multipart/form-data"> 

<table width="350" border="0" cellpadding="1" cellspacing="1" class="box" style="background-color:#0099CC;">
  <th> IMAGE UPLOAD HERE </th>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"> <p>
  <input name="upload" type="submit" class="box" id="upload" value=" Upload ">
</p></td>
</tr>
</table>
</form>
</div>
</body>
</html>