Problema di abbastanza semplice risoluzione, per rendere il tutto più sicuro sarebbe l'ideale che ad ogni immagine nel db sia legato un numero univoco, un id tanto per capirci, poi tu dove l'immagine deve apparire metti una cosa simile
Nel file thumbnail.php metterai un codice tipo questocodice:[img]thumbnail.php?id=1[/img]
In giro comunque ci sono diverse classi che fanno questa cosaCodice PHP:<?php
$ID = intval($_GET['id']);
if($ID == 0) die('Immagine non valida');
header("Content-type: image/jpeg"); // Cambia in base al tipo di file
// Possono anche essere passati tramite GET
$max_width = 100;
$max_height = 100;
//*****************************************
// Connessione al database
// Esecuzione query
$query = mysql_query("SELECT dst FROM table WHERE id = {$ID} LIMIT 1") or die('Immagine non valida');
$image = mysql_result($query, 0, 0);
//*****************************************
$info = getimagesize($image);
$width = $info[0];
$height = $info[1];
// Calcolo le nuove dimensioni
if($width > $max_width)
{
$width = $max_width;
$height = ceil($width * $info[1] / $info[0]);
}
if($new_height > $max_height)
{
$height = $max_height;
$width = ceil($height * $info[0] / $info[1]);
}
//*****************************************
$thumb = imagecreatefromjpeg($image); // Varia per ogni estensione
$newsize = imagecreatetruecolor($width, $height);
imagecopyresampled($newsize, $thumb, 0, 0, 0, 0, $width, $height, imagesx($thumb),imagesy($thumb));
imagejpeg($newsize, '', 100);
imagedestroy($thumb);
?>
![]()

Rispondi quotando