WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Convert Directory of images to a PHP Class
Categories : PHP, PHP Classes, HTML and PHP Click here to Update Your Picture
Hatem Ben
Date : Apr 09th 2004
Grade : 3 of 5 (graded 4 times)
Viewed : 3455
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Hatem Ben
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 



img2php class : Create a php class based on image directory very usefull for small packages distributions.

@package
@author Ben Yacoub Hatem <hatem@php.net>
@copyright Copyright (c) 2004
@version $Id$ - 03/04/2004 11:37:06 - img2php.class.php
@access public

<?php
class img2php{
   
/**
     * Constructor
     * @access protected
     */
   
function img2php(){
       
    }
   
   
/**
     *
     * @access private
     * @var string
     **/
   
var $_imgdir = '';
   
   
/**
     *
     * @access public
     * @return string
     **/
   
function Getimgdir(){
        return
$this->_imgdir;
    }
   
   
/**
     *
     * @access public
     * @return void
     **/
   
function Setimgdir($newValue){
       
$this->_imgdir = $newValue;
    }

   
/**
     *
     * @access private
     * @var string
     **/
   
var $_linelength = 60;
   
   
/**
     *
     * @access public
     * @return string
     **/
   
function Getlinelength(){
        return
$this->_linelength;
    }
   
   
/**
     *
     * @access public
     * @return void
     **/
   
function Setlinelength($newValue){
       
$this->_linelength = $newValue;
    }
   
   
/**
     * img2php::generate()    Read directory and Generate the php class
     *
     * @param string $_imgdir        Images directory to use
     * @param string $_classname    Class name you want to create (saved in the same dir)
     * @return
     **/
   
function generate($_imgdir = "",$_classname = ""){
        if (
$_imgdir!="") {
           
$this->Setimgdir($_imgdir);
        }
       
$d = dir($this->Getimgdir());

        while (
false !== ($entry = $d->read())) {
            if (
$entry!="." and $entry!=".." and ereg("(gif|jpg|jpeg|png)$",$entry)) {
               
$fd = fopen ($this->Getimgdir()."/".$entry, "rb");
               
$size=filesize ($this->Getimgdir()."/".$entry);
               
$ext = substr("$entry",strrpos($entry,".")+1);
               
$content = fread ($fd, $size);
               
fclose ($fd);
               
$base64img = base64_encode($content);
               
$imgcode = chunk_split($base64img,$this->Getlinelength(),"'.
'"
);

               
$fname = str_replace(".","_" , $entry);
               
$fname = str_replace("-","_" , $fname);
               
$xcase .= "
            case \"$fname\":
                gonximage::$fname();
            break;
"
;
               
$xfunx .= "    function $fname()
    {
        header(\"Content-type: image/$ext\");
        header(\"Content-length: $size\");
        echo base64_decode(
'$imgcode');
    }\n\n"
;
            }
        }
       
$d->close();

       
$data = "<?php
       
/**
* gonximage class : Generated based on directory ("
.$this->Getimgdir().")
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version \$Id$ - "
.date("Y-m-d H:i:s")." - gonximage.class.php
* @access public
**/
class gonximage{
    /**
     * Constructor
     * @access protected
     */
    function gonximage(){
       
    }
   
    /**
     * Return image based on it name
     * @access public
     * @return void
     **/
    function getimage(\$img){
        switch(\$img){
$xcase
        } // switch
    }
$xfunx
}
?>"
;
       
        if (
$_classname!="") {
           
$fp = fopen($_classname.".class.php", 'a');
           
fwrite($fp, $data);
           
fclose($fp);
        }
       
highlight_string($data);
    }
   
}

$t = new img2php;
$t->generate("images/");

?>



Class to build a select tag in html, useful to build select boxes from a data base
Categories : PHP, HTML and PHP, PHP Classes
Vote-Poll script that has a wrapper class that allows the user to create multiple polls on the same page with little trouble.
Categories : PHP, PHP Classes, HTML and PHP
Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but effective.
Categories : PHP, PHP Classes, HTML, HTML and PHP
How To Create a PDF Using PHP
Categories : PHP, PDF, PHP Classes, HTML and PHP
class formHTML build your HTML Forms from PHP
Categories : PHP, PHP Classes, HTML and PHP, HTML
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
XTemplate, a template class for PHP
Categories : PHP Classes, HTML and PHP, PHP
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
Simple class to build tables with style sheets
Categories : HTML and PHP, PHP Classes, PHP
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
very simple ftp class
Categories : PHP, PHP Classes, FTP
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP