bonjour j ai suivi le tutoriel portfolio et je rencontre un probléme avec le fichier image.php .
je suis encore un débutant et ca fait déja plus de 2 semaines que j 'essaie de trouver d'ou provien ces erreurs et meme en cherchant sur google je n'ai trouver aucune solution
[u][b]Quand j essaie d 'enregistre une image dans la partie edit j'ai ce message d 'erreur qui apparait :[/b][/u]
[u][b][/b][/u]
Fatal error: Cannot redeclare resizedName() (previously declared in C:\wamp\www\HopsStore2\lib\image.php:2) in C:\wamp\www\HopsStore2\lib\image.php on line 10
Call Stack
1 0.0010 174736 {main}( ) ..\equipements_edit.php:0
[u][b]ensuite sur la partie public quand je fai appel aux image que j avais reussi a enregistre avant cette erreur cela m affiche :[/b][/u]
[u][b][/b][/u]
( ! ) Notice: Undefined index: extension in C:\wamp\www\HopsStore2\lib\image.php on line 8
Call Stack
1 0.0020 146704 {main}( ) ..\liste_equipements.php:0
2 0.0220 184976 resizedName( ) ..\liste_equipements.php:35
masque hawaien_150x150." alt="">
Notice: Undefined index: extension in C:\wamp\www\HopsStore2\lib\image.php on line 8 Call Stack #TimeMemoryFunctionLocation 10.0020146704{main}( )..\liste_equipements.php:0 20.0220184992resizedName( )..\liste_equipements.php:35 masque hawaien_150x150." alt="">
[u][b]et sur ma 2 eme page public ce message d'erreur apparait :[/b][/u]
Notice: Undefined index: dirname in C:\wamp\www\HopsStore2\lib\image.php on line 5 Call Stack #TimeMemoryFunctionLocation 10.0010145168{main}( )..\equipement.php:0 20.0160181472resizedName( )..\equipement.php:23
( ! ) Notice: Undefined index: dirname in C:\wamp\www\HopsStore2\lib\image.php on line 6
Call Stack
1 0.0010 145168 {main}( ) ..\equipement.php:0
2 0.0160 181472 resizedName( ) ..\equipement.php:23
( ! ) Notice: Undefined index: extension in C:\wamp\www\HopsStore2\lib\image.php on line 8
Call Stack
1 0.0010 145168 {main}( ) ..\equipement.php:0
2 0.0160 181472 resizedName( ) ..\equipement.php:23
/_150x150." alt="">
[u][b]voici mes pages de codes :[/b][/u]
[i][b]pour le premier probleme:[/b][/i]
[i][b]equipement_edit.php[/b][/i]
[code]<?php
include '../lib/includes.php';
/**
La sauvegarde
**/
if(isset($_POST['name']) && 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']);
$category_id = $db->quote($_POST['category_id']);
$prix = $db->quote($_POST['prix']);
/**
* SAUVEGARDE de la réalisation
**/
if(isset($_GET['id'])){
$id = $db->quote($_GET['id']);
$db->query("UPDATE equipement SET name=$name, slug=$slug, prix=$prix, category_id=$category_id WHERE id=$id");
}else{
$db->query("INSERT INTO equipement SET name=$name, slug=$slug, prix=$prix, category_id=$category_id");
$_GET['id'] = $db->lastInsertId();
}
setFlash('L\'équipement a bien été ajoutée', 'success');
/**
* ENVOI DES IMAGES
**/
$equipement_id = $db->quote($_GET['id']);
$files = $_FILES['images'];
$images = array();
require '../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 equipement_id=$equipement_id");
$image_id = $db->lastInsertId();
$image_name = $image_id . '.' . $extension;
move_uploaded_file($image['tmp_name'], IMAGES . '/equipement/' . $image_name);
resizeImage(IMAGES . '/equipement/' . $image_name, 150,150);
$image_name = $db->quote($image_name);
$db->query("UPDATE images SET name=$image_name WHERE id = $image_id");
}
}
header('Location:equipements.php');
die();
}else{
setFlash('le slug n\'est pas valide', 'danger');
}
}
/**
/**
/**
$select = $db->query('SELECT id, name FROM categories ORDER BY name ASC');
$categories = $select->fetchAll();
$categories_list = array();
foreach($categories as $category){
$categories_list[$category['id']] = $category['name'];
}
/**
include '../partials/admin_header.php';
?>
<h1>Editer un équipement</h1>
<div class="row">
<form action="#" method="post" enctype="multipart/form-data">
<div class="col-sm-8">
<div class="form-group">
<label for="name">Nom de l'équipement</label>
<?php echo input('name'); ?>
</div>
<div class="form-group">
<label for="slug">Url de l'équipement</label>
<?php echo input('slug'); ?>
</div>
<div class="form-group">
<label for="Prix">Prix de l'équipement</label>
<?php echo textarea('prix'); ?>
</div>
<div class="form-group">
<label for="category_id">Catégorie</label>
<?php echo select('category_id', $categories_list); ?>
</div>
<?php echo csrfInput(); ?>
<button type="submit" class="btn btn-success">Enregistrer</button>
</div>
<div class="col-sm-4">
<?php foreach ($images as $k => $image): ?>
<p>
<img src="../images/works/<?php echo $image['name']; ?>" width="100"><a href="?delete_image=<?php echo $image['id']; ?>&<?php echo csrf(); ?>" onclick="return confirm('Etes vous sur de vouloir supprimé cet image ?');">Supprimer</a>
</p>
<?php endforeach ?>
<div class="form-group">
<input type="file" name="images[]">
<input type="file" name="images[]" class="hidden" id="duplicate">
</div>
<p>
<a href="#" class="btn btn-success" id="duplicatebtn">Ajouter une image</a>
</p>
</div>
</form>
</div>[/code]
[i][b]pour le deuxieme probleme :[/b][/i]
[i][b]liste_equipements.php[/b][/i]
[code]<?php
$auth = 0;
include 'lib/includes.php';
include 'partials/header.php';
$select = $db->query('SELECT name, prix FROM equipement');
$equipement = $select->fetchAll();
$select= $db->query('SELECT equipement_id FROM images');
$images = $select->fetchAll();
?>
<div id="contenu">
<div id="news">
<table class="table table-bordered table-striped table-condensed">
<caption>
<h4>Les Chapeaux</h4>
</caption>
<thead>
<tr>
<th>Nom</th>
<th>Prix</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php foreach($equipement as $equipement): ?>
<tr>
<td><?php echo $equipement['name']; ?></td>
<td><?php echo $equipement['prix']; ?></td>
</tr>
<?php endforeach; ?>
<?php foreach ($images as $k => $image): ?>
<p>
<img src="images/works/<?= resizedName($equipement['name'], 150, 150); ?>" alt="">
</p>
<?php endforeach ?>
</tbody>
</table>
</div>
<div class="clear"></div>
</div>
<?php include 'partials/footer.php'; ?>[/code]
[i][b]pour le 3 eme probleme :[/b][/i]
[i][b]equipement.php[/b][/i]
[code]<?php
$auth = 0;
include 'lib/includes.php';
$works = $db->query("
SELECT works.name, works.id, works.slug, images.name as image_name
FROM works
LEFT JOIN images ON images.id = works.image_id
")->fetchAll();
//include 'partials/header.php';
?>
<div class="row">
<?php foreach ($works as $k => $work): ?>
<div class="col-sm-3">
<a href="view.php?id=<?= $work['slug']; ?>">
<img src="images/works/<?= resizedName($work['image_name'], 150, 150); ?>" alt="">
<h2><?= $work['name']; ?></h2>
</a>
</div>
<?php endforeach ?>
</div>
</div>
<?php include 'lib/debug.php'; ?>
<?php include 'partials/footer.php'; ?>[/code]
[i][b]et le fichier image.php qui relie tous ces problemes :[/b][/i]
[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;
}
# 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]merci d'avance pour votre aide[/b]
et desoler pour ce pavé ^^