Bonsoir à toutes et tous,
J'ai réalisé l'ensemble des tutos "Créer un portfolio de A à Z", et je n'ai pas eu de souci avec la réalisation en local.
Sauf que j'ai hébergé le site, chez OVH, et je rencontre un souci avec la librairie image.php.
En fait, les images que j'envoie sont bien enregistrées en DB et dans le dossier img/works.
Mais le fichier renommé n'est pas envoyé, dans mon dossier j'ai uniquement le fichier image normal, et pas le second fichier...
Je ne vois pas bien où j'ai pu faire une erreur, la librairie d'image n'a pas changé d'un pouce.
Si quelqu'un pouvait m'aider, ça serait aimable.
[b]Voici mon image.php:[/b]
[code]<?php
function resizedName($file, $width, $height){
$info = pathinfo($file);
$return = '';
if($info['dirname'] != '.'){
$return .= $info['dirname'] . '/';
}
$return .= $info['filename'] . "_$width". "x$height." . $info['extension'];
return $return;
}
function resizeImage($file, $width, $height){
We find the right file$pathinfo = pathinfo(trim($file, '/'));
$output = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '_' . $width . 'x' . $height . '.' . $pathinfo['extension'];
# Setting defaults and meta
$info = getimagesize($file);
list($width_old, $height_old) = $info;
# Create image ressource
switch ( $info[2] ) {
case IMAGETYPE_GIF: $image = imagecreatefromgif($file); break;
case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($file); break;
case IMAGETYPE_PNG: $image = imagecreatefrompng($file); break;
default: return false;
}
var_dump($file);
# We find the right ratio to resize the image before cropping
$heightRatio = $height_old / $height;
$widthRatio = $width_old / $width;
$optimalRatio = $widthRatio;
if ($heightRatio < $widthRatio) {
$optimalRatio = $heightRatio;
}
$height_crop = ($height_old / $optimalRatio);
$width_crop = ($width_old / $optimalRatio);
# The two image ressources needed (image resized with the good aspect ratio, and the one with the exact good dimensions)
$image_crop = imagecreatetruecolor( $width_crop, $height_crop );
$image_resized = imagecreatetruecolor($width, $height);
# This is the resizing/resampling/transparency-preserving magic
if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) {
$transparency = imagecolortransparent($image);
if ($transparency >= 0) {
$transparent_color = imagecolorsforindex($image, $trnprt_indx);
$transparency = imagecolorallocate($image_crop, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
imagefill($image_crop, 0, 0, $transparency);
imagecolortransparent($image_crop, $transparency);
imagefill($image_resized, 0, 0, $transparency);
imagecolortransparent($image_resized, $transparency);
}elseif ($info[2] == IMAGETYPE_PNG) {
imagealphablending($image_crop, false);
imagealphablending($image_resized, false);
$color = imagecolorallocatealpha($image_crop, 0, 0, 0, 127);
imagefill($image_crop, 0, 0, $color);
imagesavealpha($image_crop, true);
imagefill($image_resized, 0, 0, $color);
imagesavealpha($image_resized, true);
}
}
imagecopyresampled($image_crop, $image, 0, 0, 0, 0, $width_crop, $height_crop, $width_old, $height_old);
imagecopyresampled($image_resized, $image_crop, 0, 0, ($width_crop - $width) / 2, ($height_crop - $height) / 2, $width, $height, $width, $height);
# Writing image according to type to the output destination and image quality
switch ( $info[2] ) {
case IMAGETYPE_GIF: imagegif($image_resized, $output, 80); break;
case IMAGETYPE_JPEG: imagejpeg($image_resized, $output, 80); break;
case IMAGETYPE_PNG: imagepng($image_resized, $output, 9); break;
default: return false;
}
return true;
}
?>[/code]
[b]et voici le fichier qui s'occupe de la gestion des photos:[/b]
[code]
include '../lib/includes.php';
/**
SAUVEGARDER un SLIDER
**/
if(isset($_POST['slug'])){
checkCsrf();
$slug = $_POST['slug'];
if(preg_match('/^[a-z-0-9]+$/', $slug)){
$name = $db->quote($_POST['name']);
$slug = $db->quote($_POST['slug']);
$page_id = $db->quote($_POST['page_id']);
if(isset($_GET['id'])){
$id = $db->quote($_GET['id']);
$update = $db->query("UPDATE sliders SET name=$name, slug=$slug, page_id=$page_id WHERE id=$id");
}else{
$db->query("INSERT INTO sliders SET name=$name, page_id=$page_id, slug=$slug");
}
setFlash('Le slider a bien été ajouté');
/**
ENVOI DES IMAGES
**/
$slider_id = $db->quote($_GET['id']);
$files = $_FILES['images'];
$images = array();
include '../lib/image.php';
foreach ($files['tmp_name'] as $k => $v) {
$image = array(
'name' => $files['name'][$k],
'tmp_name' => $files['tmp_name'][$k]
);
$extension = pathinfo($image['name'], PATHINFO_EXTENSION);
if (in_array($extension, array('jpg', 'png'))) {
$db->query("INSERT INTO images SET slider_id=$slider_id");
$image_id = $db->lastInsertId();
$image_name = $image_id . '.' . $extension;
move_uploaded_file($image['tmp_name'], IMAGES . '/sliders/' . $image_name);
// Redimensionnement des images
resizeImage(IMAGES . '/sliders/' . $image_name, 680, 390) . $image_name = $db->quote($image_name);
$db->query("UPDATE images SET name=$image_name WHERE id = $image_id");
}
}
header('Location:slider.php');
die();
}else{
setFlash('Le slug n\'est pas valide', 'danger');
}
}
[/code]
Merci à vous de vous pencher sur mon problème ;-)