insérer & récuperer images fonctionnel

offres2
Baptiste D 1 year ago
parent 1608d3f17d
commit ce81b7af42

@ -100,8 +100,21 @@ class UtilisateurControleur
protected function creerOffre()
{
/*
global $twig;
echo $twig->render('testImage.html', []);
/*
* */
$con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test');
$imgGw = new ImageGateway($con);
$imglist = $imgGw->getAll();
//echo $imglist[0]->getBlob();
// echo $imglist[0]->toString();
echo '<img src="data:image/jpg;base64,' . base64_encode($imglist[0]->getBlob() ). '" height="100" width="100" alt="mon image" title="image"/>';
}
@ -116,12 +129,17 @@ class UtilisateurControleur
return;
}
$con = new Connection("mysql:host=localhost;dbname=dbAlida",'test','test');
$con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test');
$imgGw = new ImageGateway($con);
$imgGw->insertImage($img);
//echo $img->getBlob();
// echo '<img src="data:image/jpg;base64,' . base64_encode($img->getBlob() ). '" height="100" width="100" alt="mon image" title="image"/>';
echo "<h1>Image inserée<h1>";
}

@ -42,50 +42,6 @@ class ImageGateway
));
}
public function updateName(int $id, string $newName)
{
$query = 'UPDATE Image SET nom=:new WHERE id=:i';
$this->con->executeQuery($query, array(
':i' => array($id, PDO::PARAM_INT),
':new' => array($newName, PDO::PARAM_STR)
));
}
public function updateDesc(int $id, string $newDesc)
{
$query = 'UPDATE Image SET desc=:new WHERE id=:i';
$this->con->executeQuery($query, array(
':i' => array($id, PDO::PARAM_INT),
':new' => array($newDesc, PDO::PARAM_STR)
));
}
public function updateTaille(int $id, string $newTaille)
{
$query = 'UPDATE Image SET taille=:new WHERE id=:i';
$this->con->executeQuery($query, array(
':i' => array($id, PDO::PARAM_INT),
':new' => array($newTaille, PDO::PARAM_STR)
));
}
public function updateType(int $id, string $newType)
{
$query = 'UPDATE Image SET type=:new WHERE id=:i';
$this->con->executeQuery($query, array(
':i' => array($id, PDO::PARAM_INT),
':new' => array($newType, PDO::PARAM_STR)
));
}
public function updateBlob(int $id, string $newBlob)
{
$query = 'UPDATE Image SET blob=:new WHERE id=:i';
$this->con->executeQuery($query, array(
':i' => array($id, PDO::PARAM_INT),
':new' => array($newBlob, PDO::PARAM_STR)
));
}
public function delete(int $id)
{
@ -112,7 +68,7 @@ class ImageGateway
$res = $this->con->getResults();
$array = [];
foreach ($res as $r) {
$array[] = new Image($r['nom'], $r['desc'], $r['taille'], $r['type'], $r['blob']);
$array[] = new Image($r['nom'], $r['taille'], $r['type'], $r['blob']);
}
return $array;

@ -15,7 +15,6 @@ class Image
/**
* @param string $name
* @param string $desc
* @param string $taille
* @param string $type
* @param string $blob
@ -50,5 +49,9 @@ class Image
return $this->blob;
}
public function toString() : string {
return "Image : " . $this->name . " " . $this->taille . " " . $this->type . " blob " . $this->blob;
}
}
Loading…
Cancel
Save