Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > MySQL
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 13-08-2003
DJ VMan DJ VMan is offline
Miembro
 
Registrado: jun 2003
Ubicación: Iquique - Chile
Posts: 81
Poder: 21
DJ VMan Va por buen camino
Guardar Imagenes en MySQL

hola!

estube viendo este hilo:

http://www.clubdelphi.com/foros/show...&threadid=2450

el cual trata de como insertar imagenes en paradox y/o interbase.

Asi que se me ocurrió hacer la siguiente pregunta, a los amigos de este lado del foro:

¿MySQL acepta guardar imagenes?
Responder Con Cita
  #2  
Antiguo 13-08-2003
Viet Viet is offline
Miembro
 
Registrado: jul 2003
Ubicación: Argentina - Mar del Plata
Posts: 252
Poder: 21
Viet Va por buen camino
Hola

Si lo Hace con los campos BLOB


Suerte
__________________
Marín Ignacio Borthiry (Viet) - "El hombre arriesga su vida cada vez que elije y eso es lo que lo hace libre" ;)
Responder Con Cita
  #3  
Antiguo 13-08-2003
DJ VMan DJ VMan is offline
Miembro
 
Registrado: jun 2003
Ubicación: Iquique - Chile
Posts: 81
Poder: 21
DJ VMan Va por buen camino
y como sería en php?
Responder Con Cita
  #4  
Antiguo 13-08-2003
Viet Viet is offline
Miembro
 
Registrado: jul 2003
Ubicación: Argentina - Mar del Plata
Posts: 252
Poder: 21
Viet Va por buen camino
Si no me equivoco seria con esto(esta algo largo ):

la clase es esta:
<?

class clsImageManager{
var $db_abstraction;
var $added_image_id;
function clsImageManager($dblayer) {

$this->db_abstraction = $dblayer;
if (!$this->db_abstraction->table_exists("images")) {
$this->db_abstraction->create_table("images","id INT NOT NULL AUTO_INCREMENT, image_data LONGBLOB NOT NULL, image_width INT NOT NULL, image_height INT NOT NULL, image_type CHAR NOT NULL, image_size INT(7) NOT NULL , PRIMARY KEY (id)");
}

}
function addImage($img_holder) {
$theInfo=getImageSize($img_holder);
if (($theInfo[2]>=1) and ($theInfo[2]<=3)) {
$fields=array("image_data","image_width","image_height","image_type","image_size");
$values=array(base64_encode(fread(fopen($img_holder, "r"), filesize($img_holder))),$theInfo[0],$theInfo[1],$theInfo[2],filesize($img_holder));
$this->db_abstraction->insert("images",$fields,$values);
$this->added_image_id=$this->db_abstraction->insert_id();
} else {
$this->added_image_id=false;
}
}
function addDirectory($thePath) {
$directory=dir($thePath);
while ($entry=$directory->read()) {
$this->addImage($entry);
}
}
function removeImage($id) {
$this->db_abstraction->delete("images","id=$id");
}
function getImageSize($id) {
$this->db_abstraction->select("*","images","id=$id");
list($id,$image_data,$image_width,$image_height,$image_type,$image_size)=$this->db_abstraction->fetch_array();
return array($image_width,$image_height,$image_type,"width=\"$image_width\" height=\"$image_height\"");
}

function getScaledImageSize($id,$maxW,$maxH) {
$this->db_abstraction->select("*","images","id=$id");
list($id,$image_data,$image_width,$image_height,$image_type,$image_size)=$this->db_abstraction->fetch_array();
if ($image_width>$maxW) {
$ratio=$maxW/$image_width;
$image_width=$image_width*$ratio;
$image_height=$image_height*$ratio;
}
if ($image_height>$maxH) {
$ratio=$maxH/$image_height;
$image_width=$image_width*$ratio;
$image_height=$image_height*$ratio;
}
return array($image_width,$image_height,$image_type,"width=\"$image_width\" height=\"$image_height\"");
}
function showImage($id) {
$this->db_abstraction->select("*","images","id=$id");
list($id,$image_data,$image_width,$image_height,$image_type,$image_size)=$this->db_abstraction->fetch_array();
switch ($image_type) {
case 1:
header("Content-type: image/gif");
print base64_decode($image_data);
break;
case 2:
header("Content-type: image/jpeg");
print base64_decode($image_data);
break;
case 3:
header("Content-type: image/png");
print base64_decode($image_data);
break;
}
}
}
?>

y utiliza esta:

<?
class db_layout {
var $classname="db_layout";

var $db_name;
var $db_user;
var $db_password;
var $db_host;
var $db_link_ptr;

var $tables;
var $fields;

}

class db_mysql extends db_layout {
var $classname="db_mysql";

var $db_result;
var $db_affected_rows;

var $saved_results=array();
var $results_saved=0;

function error($where="",$error,$errno) {
echo "$where<br>";
die($error."<br>".$errno);
}

function error_msg() {
return mysql_error();
}

function PushResults() {
$this->saved_results[$this->results_saved]=array($this->db_result,$this->db_affected_rows);
$this->results_saved++;
}

function PopResults() {
$this->results_saved--;
$this->db_result=$this->saved_results[$this->results_saved][0];
$this->db_affected_rows=$this->saved_results[$this->results_saved][1];
}

function db_mysql($host, $user, $passwd, $db, $create="") {
$this->db_name=$db;
$this->db_user=$user;
$this->db_passwd=$passwd;
$this->db_host=$host;

$this->db_link_ptr=@mysql_connect($host,$user,$passwd) or $this->error("",mysql_error(),mysql_errno());
$this->dbhandler=@mysql_select_db($db);
if (!$this->dbhandler) {
if ($create=="1") {
@mysql_create_db($db,$this->db_link_ptr) or $this->error("imposible crear la base de datos.",mysql_error(),mysql_errno());;
$this->dbhandler=@mysql_select_db($db);
}
}
}

function reselect_db($db){
$this->dbhandler=@mysql_select_db($db);
}

function closeDB() {
@mysql_close($this->db_link_ptr);
}

function create_table($tblName,$tblStruct) {
if (is_array($tblStruct)) $theStruct=implode(",",$tblStruct); else $theStruct=$tblStruct;
@mysql_query("create table $tblName ($theStruct)") or $this->error("create table $tblName ($theStruct)",mysql_error(),mysql_errno());
}

function drop_table($tblName) {
@mysql_query("drop table if exists $tblName") or $this->error("drop table $tblName",mysql_error(),mysql_errno());
}

function raw_query($sql_stat) {
$this->db_result=@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());
$this->db_affected_rows=@mysql_num_rows($this->db_result);
}

function count_records($table,$filter="") {
$this->db_result=@mysql_query("select count(*) as num from $table".(($filter!="")?" where $filter" : ""));
$xx=@mysql_result($this->db_result,0,"num");
return $xx;
}

function select($fields,$tables,$where="",$order_by="",$group_by="",$having="",$limit="") {

$sql_stat=" select $fields from $tables ";

if (!empty($where)) $sql_stat.="where $where ";
if (!empty($group_by)) $sql_stat.="group by $group_by ";
if (!empty($order_by)) $sql_stat.="order by $order_by ";
if (!empty($having)) $sql_stat.="having $having ";
if (!empty($limit)) $sql_stat.="limit $limit ";

$this->db_result=@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());
$this->db_affected_rows=@mysql_num_rows($this->db_result);

return $sql_stat;
}

function list_tables() {
$this->db_result=@mysql_list_tables($this->db_name);
$this->db_affected_rows=@mysql_num_rows($this->db_result);
return $this->db_result;
}

function describe($tablename) {
$this->result=@mysql_query("describe $tablename");
}
function table_exists($tablename) {
$this->pushresults();
$description=$this->describe($tablename);
$this->popresults();
if ($description) $exists=true; else $exists=false;
return $exists;
}
function tablename($tables, $tbl) {
return mysql_tablename($tables,$tbl);
}

function insert_id() {
return mysql_insert_id();
}

function insert($table,$fields="",$values="") {
$sql_stat="insert into $table ";

if (is_array($fields)) $theFields=implode(",",$fields); else $theFields=$fields;
if (is_array($values)) $theValues="'".implode("','",$values)."'"; else $theValues=$values;

$theValues=str_replace("'now()'","now()",$theValues);

if (!empty($theFields)) $sql_stat.="($theFields) ";
$sql_stat.="values ($theValues)";

@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());
}

function update($table,$newvals,$where="") {
if (is_array($newvals)) $theValues=implode(",",$newvals); else $theValues=$newvals;

$sql_stat="update $table set $theValues";

if (!empty($where)) $sql_stat.=" where $where";
@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());
}

function delete($table,$where="") {

$sql_stat="delete from $table ";

if (!empty($where)) $sql_stat.="where $where ";

$db_result2=@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());
$this->db_affected_rows=@mysql_affected_rows($this->db_result2);
}

function free() {
@mysql_free_result($this->db_result) or $this->error("",mysql_error(),mysql_errno());
}

function fetch_row() {
$row=mysql_fetch_row($this->db_result);
return $row;
}

function result($recno,$field) {
return mysql_result($this->db_result,$recno,$field);
}

function num_fields(){
return mysql_num_fields($this->db_result);
}

function fetch_array() {
$row=mysql_fetch_array($this->db_result);
return $row;
}

function fetch_field() {
$row=mysql_fetch_field($this->db_result);
return $row;
}
}
?>


Suerte
__________________
Marín Ignacio Borthiry (Viet) - "El hombre arriesga su vida cada vez que elije y eso es lo que lo hace libre" ;)
Responder Con Cita
  #5  
Antiguo 13-08-2003
Viet Viet is offline
Miembro
 
Registrado: jul 2003
Ubicación: Argentina - Mar del Plata
Posts: 252
Poder: 21
Viet Va por buen camino
esta es la clase que te pase
http://www.phpclasses.org/browse.html/package/979.html

y ademas necesita de esta:

http://www.phpclasses.org/goto/brows...ckage/976.html



----------------------------------------
otra forma:

http://www.onlamp.com/pub/a/php/2000...php_mysql.html



__________________
Marín Ignacio Borthiry (Viet) - "El hombre arriesga su vida cada vez que elije y eso es lo que lo hace libre" ;)
Responder Con Cita
  #6  
Antiguo 14-08-2003
DJ VMan DJ VMan is offline
Miembro
 
Registrado: jun 2003
Ubicación: Iquique - Chile
Posts: 81
Poder: 21
DJ VMan Va por buen camino
ok....muchas gracias...

le hecharé un ojo.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 15:44:54.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi