Précédent   Forum des professionnels en informatique > PHP > Langage > Fichiers
Fichiers Forum d'entraide sur les fichiers avec PHP. Avant de poster -> FAQ fichiers et Sources fichiers
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 27/07/2007, 21h29   #1
Invité de passage
 
Inscription : juillet 2007
Messages : 7
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 7
Points : 2
Points : 2
Par défaut Enregistrer un fichier image en php

Bonjour à tous,
Pour faire suite à mon dernier poste, sur la recherche ldap, j'avance bien dans mon trombinoscope.

Je suis au stade du redimenssionnement d'images.

J'ai fait simple, j'ai d'un coté mes pages du trombi et a coté (comme un deuxième site web) j'ai ma fonction de redimenssionnemet d'image.

Mon problème est le suivant : je fais parcourir pour récupérer mon image puis je fais redimenssionné. Jusque là tout est OK. Puis, j'ai un bouton "enregistrer". Lorsque je clique dessus, au lieu d'enregistrer mon image, il enregistre ma page download.php....

Ci joint les codes :

Page redimenssionnement.php (merci à son auteur) :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
 
 
<html>
<head>
 
 
</head>
<body>
<?php
if(!empty($_GET["dwn"])) {
if(!strpos(" ".$_GET["dwn"],"..")) {
header("content-type: application/octet-stream");
$f = substr($_GET["dwn"],strrpos($_GET["dwn"],"/")+1);
header("Content-Disposition: attachment; filename=".$f);
flush();
readfile($_GET["dwn"]); 
}
 
} else {
 
function redimage($img_src,$img_dest,$dst_w,$dst_h) {
// Lit les dimensions de l'image
$size = GetImageSize($img_src); 
$src_w = $size[0]; $src_h = $size[1]; 
// Teste les dimensions tenant dans la zone
$test_h = round(($dst_w / $src_w) * $src_h);
$test_w = round(($dst_h / $src_h) * $src_w);
// Si Height final non précisé (0)
if(!$dst_h) $dst_h = $test_h;
// Sinon si Width final non précisé (0)
elseif(!$dst_w) $dst_w = $test_w;
// Sinon teste quel redimensionnement tient dans la zone
elseif($test_h>$dst_h) $dst_w = $test_w;
else $dst_h = $test_h;
 
// La vignette existe ?
$test = (file_exists($img_dest));
// L'original a été modifié ?
if($test)
$test = (filemtime($img_dest)>filemtime($img_src));
// Les dimensions de la vignette sont correctes ?
if($test) {
$size2 = GetImageSize($img_dest);
$test = ($size2[0]==$dst_w);
$test = ($size2[1]==$dst_h);
}
 
// Créer la vignette ?
if(!$test) {
// Crée une image vierge aux bonnes dimensions
// $dst_im = ImageCreate($dst_w,$dst_h);
$dst_im = ImageCreateTrueColor($dst_w,$dst_h); 
// Copie dedans l'image initiale redimensionnée
$src_im = ImageCreateFromJpeg($img_src);
// ImageCopyResized($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
ImageCopyResampled($dst_im,$src_im,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
// Sauve la nouvelle image
ImageJpeg($dst_im,$img_dest);
// Détruis les tampons
ImageDestroy($dst_im); 
ImageDestroy($src_im);
}
 
// Affiche le descritif de la vignette
echo "SRC='".$img_dest."?t=".time()."' WIDTH=".$dst_w." HEIGHT=".$dst_h;
}
 
// AFFICHAGE DE LA PAGE
 
?> <font size=3>Désignez une image .JPG</font> <i>(300 Ko max.)<br>
 
<?php // GESTION DE L'UPLOAD
 
$rep="./"; // Répertoire de stockage (doit avoir les droits d'écriture ! CHMOD)
$f = $rep."original.jpg"; // path du fichier original
 
if(isset($_FILES['photo'])) {
if($_FILES['photo']['size']>0) {
if(strtolower(substr($_FILES['photo']['name'],-4))!=".jpg") { ?>
<b>Ce n'était pas un .JPG !</b>
<?php } elseif (!move_uploaded_file($_FILES['photo']['tmp_name'], $f)) { ?>
<b>Erreur d'enregistrement !</b>
<?php }
} else { ?>
<b>Trop gros fichier !</b>
<?php }
}?>
<table><FORM METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE=HIDDEN NAME=MAX_FILE_SIZE VALUE=<?php echo 300*1024;?>>
<tr><td align=center><INPUT TYPE=FILE NAME="photo"></td></tr>
<tr><td align=center><INPUT TYPE=SUBMIT value="Générer la vignette"></td></tr>
</FORM></table>
 
<?php // AFFICHAGE DE LA VIGNETTE ET DES INFOS
 
$f2 = $rep."\vignette.jpg"; // path de la vignette
$largeur=150; if(!empty($_GET["largeur"])) $largeur = $_GET["largeur"];
$hauteur=150; if(!empty($_GET["hauteur"])) $hauteur = $_GET["hauteur"];
 
if(file_exists($f)) { ?>
 
<table border=0 cellspacing=5 cellpadding=0><tr>
<td>
<center><b>Original</b></center><br>
Poids : <?php echo round(filesize($f)/1024)?> Ko<br>
Taille : <?php
$size = GetImageSize($f);
echo $size[0]."x".$size[1]; ?><br>
<br><center>
<A href="redimensionnement.php?dwn=<?php echo $f?>">Télécharger</A>
</center>
</td><td align=center>
<IMG <?php redimage($f,$f2,$largeur,$hauteur)?>>
</td><td>
<center><b>Vignette</b></center><br>
Poids : <?php echo round(filesize($f2)/1024)?> Ko<br>
Taille : <?php
$size = GetImageSize($f2);
echo $size[0]."x".$size[1]; 
$chemin="./";
$filename="vignette.jpg"; ?><br>
<br><center>
<A href="redimensionnement.php?dwn=<?php echo $f2?>">Télécharger</A>
<a href="/download.php?chemin=<?php $chemin?>&filename=<?php $filename?>">download</a>
</center>
</td>
</tr><tr>
 
<?php // CHOIX DES DIMENSIONS DE LA VIGNETTE
?>
<form><td colspan=3 align=center>
<table><tr>
<td>Largeur :</td>
<td><select name="largeur">
<?php for($i=10;$i<=150;$i+=10) {
echo "<option";
if($i==$largeur) echo " SELECTED";
echo ">".$i."</option>\n";
} ?>
</select></td>
<td>Hauteur :</td>
<td><select name="hauteur">
<?php for($i=10;$i<=150;$i+=10) {
echo "<option";
if($i==$hauteur) echo " SELECTED";
echo ">".$i."</option>\n";
} ?>
</select></td>
<td><input type=submit value=Modifier></td>
</td></form>
</tr></table>
 
<?php } ?>
 
</td>
</tr></table></center>
<?php
 
} ?>
</body>
</html>
Puis le code de la page download :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
<?php
 
header("Content-Disposition: attachment; filename=".$filename); 
header("Content-type: application/force-download" ); 
header("Content-Transfer-Encoding: image/jpeg\n"); // Surtout ne pas enlever le \n
header("Content-Length: ".filesize($chemin . $Filename)); 
header("Pragma: no-cache"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public"); 
header("Expires: 0");  
readfile($chemin.$filename); 
 
?>
Dans la page redimenssionnement.php, cela bug au moment ou je clique sur (il y a deux liens, pr mes tests : le premier correspond au fichier original et le deuxième à mes tests, j'ai rajouté en dur $chemin et $filename qui ne change pas car au moment d'enregistrer je pourrai changer de nom):
Code :
1
2
3
4
 
 
<A href="redimensionnement.php?dwn=<?php echo $f2?>">Télécharger</A>
<a href="/download.php?chemin=<?php $chemin?>&filename=<?php $filename?>">download</a>
Voilà mon problème, pourquoi me propose t'il d'enregistrer le fichier php au lieu de mon image

Merci pour vos futures réponses.

Ed
Eddu37 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2007, 21h48   #2
Membre éclairé
 
Avatar de nicocsgamer
 
Inscription : mars 2005
Messages : 324
Détails du profil
Informations personnelles :
Âge : 27
Localisation : Luxembourg

Informations forums :
Inscription : mars 2005
Messages : 324
Points : 365
Points : 365
Envoyer un message via MSN à nicocsgamer
Citation:
<a href="/download.php?chemin=<?php echo $chemin;?>&filename=<?php echo $filename;?>">download</a>
nicocsgamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2007, 22h21   #3
Invité de passage
 
Inscription : juillet 2007
Messages : 7
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 7
Points : 2
Points : 2
Salut nicocsgamer,

Merci pour ta réponse.
Je viens d'essayer tes modifs. Rien à faire.....

Il veut tjs m'enregistrer mon fichier php.....
Eddu37 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2007, 22h25   #4
Membre éclairé
 
Avatar de nicocsgamer
 
Inscription : mars 2005
Messages : 324
Détails du profil
Informations personnelles :
Âge : 27
Localisation : Luxembourg

Informations forums :
Inscription : mars 2005
Messages : 324
Points : 365
Points : 365
Envoyer un message via MSN à nicocsgamer
Essaye la fonction fpassthru() au lieu du readfile.
nicocsgamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2007, 22h32   #5
Invité de passage
 
Inscription : juillet 2007
Messages : 7
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 7
Points : 2
Points : 2
Toujours pareil.

Sinon, lorsque je clique sur le bouton "telecharger", j'ai ça (et j'en passe):

Code X :
1
2
3
4
Warning: Cannot modify header information - headers already sent by (output started at C:\hotline\wamp\www\redimensionnement.php:7) in C:\hotline\wamp\www\redimensionnement.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at C:\hotline\wamp\www\redimensionnement.php:7) in C:\hotline\wamp\www\redimensionnement.php on line 12
ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC    $.' ",#(7),01444'9=82<.342ÿÛC  2!!22222222222222222222222222222222222222222222222222ÿÀ–j"ÿÄ ÿĵ}!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š
Eddu37 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2007, 23h23   #6
Membre éclairé
 
Avatar de nicocsgamer
 
Inscription : mars 2005
Messages : 324
Détails du profil
Informations personnelles :
Âge : 27
Localisation : Luxembourg

Informations forums :
Inscription : mars 2005
Messages : 324
Points : 365
Points : 365
Envoyer un message via MSN à nicocsgamer
Tu ne peux pas modifier les header après avoir affiché des données.
nicocsgamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/07/2007, 20h02   #7
Invité de passage
 
Inscription : juillet 2007
Messages : 7
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 7
Points : 2
Points : 2
Re,

Ca y est...J'ai trouvé....

Dans mon fichier redimensionnement.php, j'ai mis cette ligne à la place des href :

Code :
1
2
 
<a href="down3.php?photo=vignette.jpg">Enregistrer l'image réduite</a>
Puis dans mon fichier down3.php :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
<?php 
$filename = $_GET['photo']; 
header('Content-Type: application/octet-stream'); 
 
if (preg_match('/MSIE 5.5/', $_ENV['HTTP_USER_AGENT']) || preg_match('/MSIE 6.0/', $_ENV['HTTP_USER_AGENT'])){  
    header('Content-Disposition: filename = "'.$filename.'"');  
} else {  
    header('Content-Disposition: attachment; filename = "'.$filename.'"');  
} 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($filename)); 
readfile($filename); 
exit(); 
?>

Merci nicocsgamer pour tes propositions et pour le temps que tu as consacré à mon pb.
J'espère que mon petit souci servira à d'autres....

Bon courage. Tchao
Eddu37 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 20h32.


 
 
 
 
Partenaires

Hébergement Web