PHP Classes

File: _image.php

Recommend this page to a friend!
  Classes of Tiana Rakoto   Image SQL manager   _image.php   Download  
File: _image.php
Role: Application script
Content type: text/plain
Description: output framework with manager
Class: Image SQL manager
Display and store images in a MySQL database
Author: By
Last change:
Date: 17 years ago
Size: 4,221 bytes
 

Contents

Class file image Download
<?php
/*!
@copyrights b23|prod:Tiana Bruno RAKOTOARIMANANA - 2004 (all rights reserved to author)
@author Tiana Bruno RAKOTOARIMANANANA
@date :brunorakotoarimanana:20050110
@filename _image.php
*/

define("FORCE_DEBUG", true);
if(
FORCE_DEBUG) error_reporting(E_ALL);
define("SERVEUR", "localhost");
define("BASE", "broumbroum23_db");
define("NOM", "broumbroum23");
define("PASSE", "");/*
define("SERVEUR", "mysql4-p");
define("BASE", "p163092_");
define("NOM", "p163092rw");
define("PASSE", "");*/
/*!
@script image
@param id, size. fourni en _GET ou _POST
#id: id de l'image de la table SQL "image".
#size: dimensions de l'image: int(3)[%] ou array(int(4)[px],int(4)[px])
ou
#file: urlencode($filename)
*/
require_once("include/php_image.class.inc.php");
require_once(
"include/php_imageSQL.class.inc.phps");
require_once(
"include/php_SQL.class.inc.php");
require_once(
"include/php_tbl.class.inc.php");
require_once(
"include/php_formulaire.class.inc.php");

$sql = new SQL(SERVEUR,BASE,NOM,PASSE);
$image=new Image(FORCE_DEBUG);

// MANAGEMENT PART
if(isset($_GET["manage"])) {
    if(
imagetypes() & IMG_PNG) $mime_types[".PNG"] = "image/png";
    if(
imagetypes() & IMG_JPG) $mime_types[".JPEG"] = "image/jpeg";
    if(
imagetypes() & IMG_WBMP) $mime_types[".WBMP"] = "image/wbmp";
    if(
imagetypes() & IMG_GIF) $mime_types[".GIF"] = "image/gif";
   
    if(isset(
$_GET['load'])) {
       
$res = $sql->query("SELECT id FROM image WHERE nom='".addSlashes($_POST['filename'])."'");
       
$img = $sql->LigneSuivante($res);
       
$id = $img[0];
        if(
$id == null) die("No data found for query ".$_POST['filename']."!");
       
$image = new ImageSQL($sql, $id);
       
$image->setMime($_POST['mime']);
       
$image->display('h');
    }
   
   
$f = new Formulaire("Load from database", $_SERVER['SCRIPT_URL']."?manage=1&load=1");
   
$f->ajouterChamp(new ChampTexte("filename","Filename","",20));
   
$f->ajouterChamp(new ChampSelect("mime","Mime type","",$mime_types,1));
   
$f->ajouterChamp(new ChampValider("Load it!"));
   
$f->ajouterChamp(new ChampEffacer("reset fields"));
   
$f->fin(1);
   
    if(isset(
$_GET['save'])) {
       
$image->setMime($_POST['mime']);
       
$image->setNom($_FILES['file']['name']);
        echo
$image->nom."\r\n";
        if(!
$image->loadFromFile($_FILES['file']['tmp_name']))
            die(
"Erreur de chargement!".$_FILES['file']['tmp_name']."\n");
        echo
$image->nom."\n";
       
$id = $image->saveToSQL($sql);
       
error_reporting(E_NOTICE);
       
trigger_error("MySQL DB affected by ".mysql_affected_rows($sql->connexion), E_NOTICE);
       
$imageSQL = new ImageSQL($sql,$id);
       
$imageSQL->display('h');
    }
   
   
$f = new Formulaire("Save to database", $_SERVER['SCRIPT_URL']."?manage=1&save=1");
   
$f->ajouterChamp(new ChampFile("file", "Select file to upload", 'post_max_size = ' . @ini_get('post_max_size'), @ini_get('post_max_size')));
   
$f->ajouterChamp(new ChampSelect("mime", "Mime type", "", $mime_types,1));
   
$f->ajouterChamp(new ChampValider("Save it!"));
   
$f->ajouterChamp(new ChampEffacer("reset"));
   
$f->fin(1);
   
   
$sql->close();
    exit();
}
// PRINTING PART
else if(!isset($_GET["id"])) {
    if(isset(
$_GET["file"])) {
        if(isset(
$_GET["size"])) {
           
$image->setSize($_GET["size"]);
           
$image->resize();
        }
       
$image->loadFromFile(urldecode($_GET['file']));
    } else
$image->loadError();
   
$image->afficher(1);
    exit();
} else {
   
// connexion SQL
   
   
$image = new ImageSQL($sql,$_GET["id"], FORCE_DEBUG);
    if(isset(
$_GET["size"])) {
       
$image->setSize($_GET["size"]);
       
$image->resize();
    }
    if(isset(
$_GET["frame"])) {
       
ob_start();
       
$image->display('h');
       
$pAdmin = new tableau(1,2,"image".$_GET["size"], BIG);
       
$pAdmin->setContenu_Cellule(0,0,"<link rel=stylesheet href='stylesheet.css' type='text/css'>");
       
$pAdmin->setContenu_Cellule(0,1,"<center>".ob_get_contents()."<BR>&copy; 2005-2006 :::... :... :::::: ;;;::;&#153;</center>");
       
$pAdmin->fin();
       
$sql->close();
        exit();
    }
    if(isset(
$_GET["tag"])) {
       
$image->display('h');
        exit();
    }
   
$image->display('o');
}
?>