Ta chaîne de caractère inscrite dans le fichier est coupée à cause des simples quotes utilisées dans les variables.
Il faut échapper ces caractères.
Exemple :
// correct
$var = 'L\'art des quotes';
// incorrect
$var = 'L'art des quotes';
$_GET['pic\']
$_GET['h_max\']
$_GET['w_max\']
<?php
error_reporting(-1);
$taille = getimagesize($_GET['pic']);
$h_i = $taille[1];
$w_i = $taille[0];
if($h_i >$_GET['h_max'])
{
$convert=$_GET['h_max']/$h_i;
$h_i=$_GET['h_max'];
$w_i=ceil($w_i*$convert);
}
if($w_i >$_GET['w_max'])
{
$convert=$_GET['w_max']/$w_i;
$w_i=$_GET['w_max'];
$h_i=ceil($h_i*$convert);
} ;
$largeur = "$w_i";
$hauteur ="$h_i";
header("Content-Type: image/jpeg");
list($width, $height, $type, $attr) = getimagesize($_GET['pic']);
if($type == "1")
{
$img_in = imagecreatefromgif($_GET['pic']);
}
if($type == "2")
{
$img_in = imagecreatefromjpeg($_GET['pic']);
}
if($type == "3")
{
$img_in = imagecreatefrompng($_GET['pic']);
}
$img_out = imagecreatetruecolor($largeur, $hauteur);
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
$t = imagejpeg($img_out);
echo $t;
?>
<?php
error_reporting(-1);
$taille = getimagesize($_GET[\'pic\']);
$h_i = $taille[1];
$w_i = $taille[0];
if($h_i >$_GET[\'h_max\'])
{
$convert=$_GET[\'h_max\']/$h_i;
$h_i=$_GET[\'h_max\'];
$w_i=ceil($w_i*$convert);
}
if($w_i >$_GET[\'w_max\'])
{
$convert=$_GET[\'w_max\']/$w_i;
$w_i=$_GET[\'w_max\'];
$h_i=ceil($h_i*$convert);
} ;
$largeur = "$w_i";
$hauteur ="$h_i";
header("Content-Type: image/jpeg");
list($width, $height, $type, $attr) = getimagesize($_GET[\'pic\']);
if($type == "1")
{
$img_in = imagecreatefromgif($_GET[\'pic\']);
}
if($type == "2")
{
$img_in = imagecreatefromjpeg($_GET[\'pic\']);
}
if($type == "3")
{
$img_in = imagecreatefrompng($_GET[\'pic\']);
}
$img_out = imagecreatetruecolor($largeur, $hauteur);
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
$t = imagejpeg($img_out);
echo $t;
?>
<?php
$repdossier = $_GET['repdossier'];
$uploaddir = 'upload/'.$repdossier.'/';
$file = $uploaddir . basename($_FILES['uploadfile']['name']);
$dir2 = opendir("upload/$repdossier/");
$getpages=0;
while ($File = readdir($dir2)){
if($File != "." && $File != ".." && $File != "" )
{ $getpages++;
}
}
closedir($dir2);
$calcul = $getpages;
if( @is_file($file) )
{
echo "error2";
}
else
{
if( $calcul >= 5)
{
echo "error1";
}
else
{
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
echo "success";
} else {
echo "error";
}
}
}
?>
<?php echo "<a href='javascript:deleteImg(".$ligne["id_image"].",".$ligne["id_gallerie"].")'>Supprimer l'image</a>"; ?>
Et l'ai intégrer comme cela dans le fichier all.index.php<?php
$repdossier = $_GET['repdossier'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>AJAX File Upload - Web Developer Plus Demos</title>
<script type="text/javascript" src="js/jquery-1.3.2.js" ></script>
<script type="text/javascript" src="js/ajaxupload.3.5.js" ></script>
<link rel="stylesheet" type="text/css" href="./styles.css" />
<script type="text/javascript" >
$(function(){
var btnUpload=$('#upload');
var status=$('#status');
new AjaxUpload(btnUpload, {
<?php
echo "action: 'upload-file.php?repdossier=".$repdossier."',";
?>
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// extension is not allowed
status.text('Les extentions possible sont JPG, PNG ou GIF');
return false;
}
status.html('Envoi en cours <img src="images/loadingup.gif?<?php echo md5(time()); ?>" border="0" height="6" width="19">');
},
onComplete: function(file, response){
//On completion clear the status
status.text('');
//Add uploaded file to list
if(response==="success"){
$('<li></li>').appendTo('#files').html('<img src="miniature.php?pic=upload/<?php echo $repdossier; ?>/'+file+'&w_max=70&h_max=60" height="60" width="70" alt="" /><br />').addClass('success');
}
if(response==="error1"){
alert("Vous avez déjà 5 photos pour votre annonce !\nLe maximum de photos autorisées est de 5 !")
}
if(response==="error2"){
alert("La photo selectionnée existe déjà\nRe-selectionnez une autre photo !")
}
}
});
});
</script>
<script type="text/javascript">
function deleteImg(id_img,id_gal) {
if (confirm ("Voulez-vous vraiment effacer cette image ?")) {
document.location.replace("ma_page.php?action=efface_img&id_img="+id_img+"&id_gal="+id_gal);
}
}
</script>
</head>
<body>
<div id="mainbody" >
<div id="upload" ><span>Ajouter des photos<span></div><span id="status" ></span>
<ul id="files" ></ul>
</div>
<?php echo "<a href='javascript:deleteImg(".$ligne["id_image"].",".$ligne["id_gallerie"].")'>Supprimer l'image</a>"; ?>
</body>
</html>
Cependant j'ai bien le bouton "Supprimer l'image" mais aucune action une idée pourquoi le bouton ne s'actionne pas ?<?
// Suppression d'un fichier
unlink("../upload");
// Vérification de l'existance du fichier avant de la supprimer
if(file_exists("dossiers/monfichier.png")){
unlink("upload");
echo "Le fichier a été supprimé";
}else{
echo "Le fichier n'existe pas !"
}
?>
2ème méthode
<?php
/* Fichier à supprimer */
$fichier = 'upload';
if( file_exists ( $fichier))
unlink( $fichier ) ;
Alternative:
@unlink( $fichier ) ;?>
3eme méthode<?php
foreach(glob('upload/*') as $repdossier) {
if(!strpos($repdossier, 'pic') && !strpos($repdossier, '.jpg')) {
unlink($repdossier);
}
}
?>
$liste = glob('upload/pic_*.jpg');
Pour le script que tu as essayé si le script JS ne s'exécute pas c'est qu'une erreur est déclenchée.<?php
$liste = glob('upload/pic_*.jpg');
if(!strpos($repdossier, 'pic_*.jpg');
unlink($repdossier);
?>