PHP Classes

File: example2

Recommend this page to a friend!
  Classes of ubaidullah khan  >  Easy upload resize thumb image  >  example2  >  Download  
File: example2
Role: Example script
Content type: text/plain
Description: this example demonstrat that how can use class with database
Class: Easy upload resize thumb image
Resize uploaded image files
Author: By
Last change:
Date: 12 years ago
Size: 3,115 bytes


Class file image Download

$_REQUEST['Action']) && $_REQUEST['Action'] == 'UploadNew')
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$i = 0; $i < count($_FILES['Comic']['name']); $i++)
//create object that will upload and resize image
                //save image information in db
mysql_query("insert into image(ImageName, ImagePath) values('".$_FILES['Comic']['name'][$i]."','pictures/')");

$UF_obj = new Upload();
$UF_obj -> File = $_FILES['Comic'];
$UF_obj -> SavePath = 'pictures'; // PLACE where you want to save images.
$UF_obj -> ThumbPath = 'pictures/thumb'; //if not specify will not create thumbnil
$UF_obj -> NewName = $_FILES['Comic']['name'];
//width and height of large image which will save in "pictures/" folder
$UF_obj -> NewWidth = 300;
$UF_obj -> NewHeight = 300;
////width and height of thumb image which will save in "pictures/thumb/" folder
$UF_obj -> TWidth = 50;
$UF_obj -> THeight = 50;

        * if you want to name image something other then upload image name then use bellow formate
        * for example you upload two images then
        * $UF_obj -> NewName = array('NewName1.jpg', 'NewName2.jpg');
$UF_obj -> NameCase = 'lower'; //default no change. upper for upper case
$UF_obj -> OverWrite = true; //default = true. replace existing image
        //UploadFile() function upload and resize image.
        //function return error message if any.
        //error variable is in array form. so you can get more then one error/warning messages.
        // or you can also access error message by class object varialbe like $UF_obj -> Error
$Error = $UF_obj -> UploadFile();
count($Error) > 0 and is_array($Error))
$Error as $key=>$val)
$val . '<br>';
//end of for loop

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<form action="" target="_self" method="post" enctype="multipart/form-data">
  <table border="0" cellpadding="4" cellspacing="0" width="100%">
      <td> First Image: </td>
      <td><input type="file" name="Comic[]" id="Comic" /> </td>
      <td> Second Image: </td>
      <td><input type="file" name="Comic[]" id="Comic" /> </td>
      <td colspan="2"><input type="hidden" name="Action" value="UploadNew" />
          <input type="submit" name="submit" value="Upload" /> </td>

For more information send a message to info at phpclasses dot org.