Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
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/12/2011, 12h30   #1
Invité de passage
 
Femme Laetitia Gibout
Consultant en technologies
Inscription : décembre 2011
Messages : 4
Détails du profil
Informations personnelles :
Nom : Femme Laetitia Gibout
Localisation : Suisse

Informations professionnelles :
Activité : Consultant en technologies
Secteur : Tourisme - Loisirs

Informations forums :
Inscription : décembre 2011
Messages : 4
Points : 0
Points : 0
Par défaut Script qui redimensionne les images

Bonjour!!

Je ne connais pas bien php mais jai un petit probleme de script qui redimentionne les images en grand a une mesure précise et jaimerais annuler ca (pcq si un user envoi pas une aux dimensions enorme, ca fait plein de pixel donc jaimerais garder la taille d'origine)

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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
// init
error_reporting(E_ERROR|E_PARSE);
session_start();
//echo "MM".$_SESSION["MYLANG"];
require_once("includes/config.php");
require_once("includes/fonctions.php");
require_once("includes/languages/".$_SESSION["MYLANG"]."/lang.php");
$allowUpload = count($_SESSION['imgToAdd'])<(PHOTO_MAX_COUNT-1);
$allowUploadImg = count($_SESSION['imgToAdd'])<(PHOTO_MAX_COUNT);
if (!isset($_SESSION['imgToAdd'])) $_SESSION['imgToAdd'] = array();
getConfig();
$uploadDir = 'images_upload';
handleThePost();
$displayPicFrame = count($_SESSION['imgToAdd'])>0;
?>
<?php
// handle post func
function handleThePost()
{
	global $allowUploadImg;
	if ($allowUploadImg && isset($_FILES['new_file']) && $_FILES['new_file']['error']==UPLOAD_ERR_OK)
	{
		global $uploadDir;
		$newFn = $uploadDir.'/'.time().'.jpg';
		move_uploaded_file($_FILES['new_file']['tmp_name'], $newFn);
		$_SESSION['imgToAdd'][] = $newFn;
	}
}
?>	
<html>
<head>
<link rel="stylesheet" type="text/css" href="js/sb/shadowbox.css" />
<script type="text/javascript" src="js/sb/shadowbox.js"></script>
<script type="text/javascript">
Shadowbox.init();
</script>
 
<title>Upload pictures</title>
<script type="text/javascript">
var pics = 
[
<?php
$picsAry = array();
for ($i = 0 ; $i < count($_SESSION['imgToAdd']); $i++)
{
//	$picsAry[] = "$i: '".$_SESSION['imgToAdd'][$i]."'";
	$picsAry[] = "'".$_SESSION['imgToAdd'][$i]."'";
}
print join(",\n", $picsAry);
?>
];
function setPicFrame(cnt)
 
{
	document.getElementById('bigPic').src = pics[cnt];
	document.getElementById('bigPicLink').className = pics[cnt];
	if (cnt == pics.length-1)
	{
		document.getElementById('righta').src = 'images/right-nonclickable.gif';
	}
	else
	{
		document.getElementById('righta').src = 'images/right-clickable.gif';
	}
	if (cnt == 0)
	{
		document.getElementById('lefta').src = 'images/left-nonclickable.gif';
	}
	else
	{
		document.getElementById('lefta').src = 'images/left-clickable.gif';
	}
	<?php
	for($i = 0 ; $i < count($_SESSION['imgToAdd']); $i++)
	{
		?>
	removeCSSClass(document.getElementById(pics[<?php echo $i ; ?>]), 'around');
		<?php
	}
	?>
	addCSSClass(document.getElementById(cnt), "around");
}
 
function removeCSSClass(obj, cls)
{
if (obj==null) return;
obj.className = obj.className.replace(cls,' ')
}
 
function addCSSClass(obj, cls)
{
if (obj==null) return;
obj.className += ' ' + cls
}
 
function doShadowbox(obj)
{
	str = obj.className;
	options = {
		content: str,
		player: "img",
		top:0,
		bottom:0,
		options: {
		handleOversize: "resize",
		autoDimensions:true,
		initialHeight: 640,
		viewportPadding: -5,
		overlayColor: "#FFF",
		overlayOpacity: 0
		}
	};
 
	Shadowbox.open(options);
}
 
 
var curPic = 0;
function prevPic(elmt)
{
	if (curPic == 0) 
	{
		elmt.src="images/left-nonclickable.gif";
		setPicFrame(0);
		return;
	}
	else
	{
		curPic--;
		if (curPic==0) elmt.src = "images/left-nonclickable.gif";
		setPicFrame(curPic);
	}
}
 
function nextPic(elmt)
{
	if (curPic >= pics.length - 1)
	{
		elmt.src = "images/right-nonclickable.gif";
		setPicFrame(pics.length-1);
		return;
	}
	else
	{
		curPic++;
		if (curPic==pics.length-1) elmt.src="images/right-nonclickable.gif";
		setPicFrame(curPic);
	}
}
</script>
<style type="text/css">
<style type="text/css">
.body
{
width: 300px;
height: 200px;
border:none;
}
.around
{
border: 1px solid gray;
	font-family: Verdana, Arial, sans-serif;
}
 
.resizedBigPic
{
	height:auto!important;
	width:auto!important;
	width:120px;
	max-height: 120px;
	max-width: 300px;
 
}
 
.resizedSmallPic
{
	height:auto!important;
	width:auto!important;
	height: 60px;
	float:left;
	display:block;
	max-height:60px;
	border: 1px solid white;
}
 
#smallPics
{
width: 300px;
overflow:scroll;
}
 
#aroundDiv 
{
margin-left: 15px;
}
#thewrapper
{
 
width: 300px;
height: 200px;
}
.aroundWrapper
{
<?php
echo "/* auto generated piece of css*/\n";
echo "width: ".(PHOTO_MAX_COUNT*90)."px";
?>
}
 
#bigPicLink
{
font-size: 0.8em;
 
}
#bigPic
{
margin-top: 5px;
padding-left: 3px;
padding-right: 3px;
padding-top: 20px;
padding-bottom: 20px;
border: 1px solid gray;
}
 
#uploadField
{
margin-left: 11px;
}
#bpFrame
{
width:300px;
height:150px;
}
#leftrightarrow
{
float: right;
}
</style>
</head>
<body class="body">
<div id="thewrapper">
<?php
if ($displayPicFrame)
{
$cn = max(count($_SESSION['imgToAdd'])-1, 0);
 
$imgToShow = $_SESSION['imgToAdd'][$cn];
?>
	<div class="around" id="aroundDiv">
		<center>
			<div id="bpFrame">
			<img id="bigPic" src="<?php echo $imgToShow ; ?>" class="resizedBigPic" /><br />
			</div>
		</center>
		<div style="margin-top:20px;" class="navbar">
			<a style="display:block; float:left;" href="#" id="bigPicLink" onclick="doShadowbox(this);return false;" class="<?php echo $imgToShow ;?>"><?php _ts("View larger image"); ?></a>	
			<div id="leftrightarrow"><img src="images/left-nonclickable.gif" id="lefta" onclick="prevPic(this)" /> <img src="images/right-<?php echo count($_SESSION['imgToAdd'])<=1?'non':''; ?>clickable.gif" id="righta" onclick="nextPic(this)"/></div>
		</div>
		<div class="around" id="smallPics">
		<div class="aroundWrapper">
<?php
	for ($i = 0; $i < count($_SESSION['imgToAdd']); $i++)
	{
		$image = $_SESSION['imgToAdd'][$i];
		$greyed = ($image==$imgToShow);	
		?>
			<img id="<?php echo $image; ?>"class="resizedSmallPic<?php $greyed?' around':''?>" onclick="setPicFrame(<?php echo $i; ?>)" src="<?php echo $image ; ?>" />
		<?
	}
	?>
		</div>
		</div
	</div>
	<?php
} // end if displayPicFrame
?>
<form enctype="multipart/form-data" method="post" action="img_upload.php">
<table>
<tr><td><input id="uploadField" <?php echo $allowUpload?'':'disabled' ;?> type="file" name="new_file" id="new_file" /></td></tr>
<tr><td><input type="submit" style="margin-left:10px;"value="<?php _ts("Send image"); ?>"<?php echo $allowUpload?'':'disabled' ;?></td></tr>
</table> 
</form>
</div>
</body>
</html>
Laetitia7771 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/01/2012, 15h21   #2
Modératrice
 
Avatar de Celira
 
Femme
Développeuse PHP/Java
Inscription : avril 2007
Messages : 3 671
Détails du profil
Informations personnelles :
Sexe : Femme
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeuse PHP/Java

Informations forums :
Inscription : avril 2007
Messages : 3 671
Points : 5 404
Points : 5 404
Je ne vois pas le code qui fait le redimensionnement dans ton extrait. Est-ce que c'est fait à la réception du formulaire ?
__________________
Modératrice PHP
Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)

Pour afficher votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur)
Celira est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 18h58.


 
 
 
 
Partenaires

Hébergement Web