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 18/03/2011, 16h03   #1
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Par défaut Envoi de fichier en http

Bonjour
Je poste sans grand espoir de réponse, car c'est curieux...
Je cherche à envoyer une photo prise de l'appareil vers internet (pour la recevoir via php).
J'ai essayé avec org.apache.http via la méthode PUT et POST.
Dans les 2 cas, le fichier est bien transmit, mais il y a une erreur de quelques octets en moins et l'image est donc illisible.

Voici le code d'envoi POST :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
 
// data est un byte[]
 
// requette
HttpPost req = new HttpPost(URL_SEND_PHOTO);
 
MultipartEntity multipart = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
multipart.addPart("photo", new ByteArrayBody(datas, "nom"));
req.setEntity(multipart);
 
// execute la requette
HttpResponse response = httpclient.execute(req);
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/03/2011, 22h43   #2
Membre habitué
 
Inscription : décembre 2007
Messages : 176
Détails du profil
Informations forums :
Inscription : décembre 2007
Messages : 176
Points : 111
Points : 111
Juste une suggestion : utilisé un OutputStream qui gère les flux via les Http ?

Je n'ai pas testé mais c'est peut-être une piste
LordDaedalus est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 11h10   #3
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par LordDaedalus Voir le message
Juste une suggestion : utilisé un OutputStream qui gère les flux via les Http ?

Je n'ai pas testé mais c'est peut-être une piste
Merci pour ta réponse mais, je ne voie pas exactement de quoi tu parles.
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 12h06   #4
Modérateur
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 16 191
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 16 191
Points : 25 347
Points : 25 347
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
est vous sur qu'il ne manque pas déjà des données dans data[] plutot? Pourriez vous comparer data.length et la taille que votre application php recois?
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
"Votre génitrice tute des pédoncules au pandémonium" (le conjurateur, 1973)
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 14h05   #5
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par tchize_ Voir le message
est vous sur qu'il ne manque pas déjà des données dans data[] plutot? Pourriez vous comparer data.length et la taille que votre application php recois?
J'utilise data[] pour d'une part, envoyer au serveur et d'autre part, enregistrer en local.
Hors en local, l'image est OK.
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 15h20   #6
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Un exemple de données

Photo en local : 761063 octets
Photo sur le serveur : 761053 octets
Information de $_FILE['fichier']['size'] en php : 761063 octets
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 15h31   #7
Modérateur
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 16 191
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 16 191
Points : 25 347
Points : 25 347
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
Manifestement vous recevez donc le fichier complet en PHP mais ne le sauvez pas entièrement => C'est plutot un problème de PHP
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
"Votre génitrice tute des pédoncules au pandémonium" (le conjurateur, 1973)
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 17h28   #8
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par tchize_ Voir le message
Manifestement vous recevez donc le fichier complet en PHP mais ne le sauvez pas entièrement => C'est plutot un problème de PHP
Arg, mon poste n'est plus dans le forum Android ! Merci.
Pourtant je crois bien que c'est un souci avec Android ou Java.
Car, pour la reception PHP, rien de + simple, ce qui fonctionne dans tout les autres cas :

Code :
1
2
3
4
5
6
 
// enregistrement de l'image
if( isset($_FILES['photo']) ){
	$tmp_file = $_FILES['photo']['tmp_name'];
	move_uploaded_file($tmp_file, $cheminPhoto);
}
Sinon, via la méthode PUT :

Code :
1
2
3
4
5
6
7
8
 
$putdata = fopen("php://input", "r");
$fp = fopen($cheminPhoto, "w");
while ( $data = fread($putdata, 512)){
 	fwrite($fp, $data);
}
fclose($fp);
fclose($putdata);
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 18h06   #9
Modérateur
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 16 191
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 16 191
Points : 25 347
Points : 25 347
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
je lit ce que vous dites:
Citation:

Photo sur le serveur : 761053 octets
Information de $_FILE['fichier']['size'] en php : 761063 octets
Donc PHP a bien recu le ficheir complet, mais il se fait casser quelque part.
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
"Votre génitrice tute des pédoncules au pandémonium" (le conjurateur, 1973)
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 18h10   #10
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Je viens de tester en Java, car j'ai déjà eu un souci présent uniquement sous Android.
C'est le même dilemme en java.

Je poste donc le code complet :

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
 
package net.monsite;
 
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
 
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.impl.client.DefaultHttpClient;
 
public class Connexion {
	private static final String URL_SEND_PHOTO = "http://monsite.net/send_photo.php";
 
	// envoi d'un fichier
	public static void sendGeoPhoto(byte[] datas)
			throws IOException {
		// client
		HttpClient httpclient = new DefaultHttpClient();
		// requette
		HttpPost req = new HttpPost(URL_SEND_PHOTO);
		// multipart
		MultipartEntity multipart = new MultipartEntity(
				HttpMultipartMode.BROWSER_COMPATIBLE);
		multipart.addPart("photo", new ByteArrayBody(datas, "nom"));
		req.setEntity(multipart);
		// execute la requette
		httpclient.execute(req);
	}
 
	// récupération du fichier dans un tableau de byte
	private static byte[] stream2Byte(InputStream is) throws IOException {
		byte[] buffer = new byte[1024];
		ByteArrayOutputStream datas = new ByteArrayOutputStream();
		int l;
		while ((l = is.read(buffer)) > 0) {
			datas.write(buffer, 0, l);
		}
		return datas.toByteArray();
	}
 
	// MAIN
	public static void main(String[] args) throws IOException {
		File fichier = new File("photo.jpg");
		FileInputStream is = new FileInputStream(fichier);
		byte[] tableau = stream2Byte(is);
		sendGeoPhoto(tableau);
	}
}
Je pense que cela doit venir de la configuration du client HTTP car sinon, je ne vois pas...
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 18h16   #11
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par tchize_ Voir le message
je lit ce que vous dites:
Donc PHP a bien recu le ficheir complet, mais il se fait casser quelque part.
N'est-ce pas qu'une information, la taille dans $_FILE['fichier']['size'], envoyée par le client ?

Dans tous les cas, la réception php est tellement simple et rodée que je ne vois pas comment cela pourrait venir de là...

J'ai tout-de-même essayé sur autre serveur dans le doute, mais l'erreur persiste.
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 22h28   #12
Membre Expert
 
Inscription : septembre 2010
Messages : 1 242
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 1 242
Points : 1 564
Points : 1 564
ça le fait sur toutes les images que tu envoies ? Sinon ça pourrait peut-être venir du fait qu'une image est corrompue
__________________
- Réalisations
- Interface graphique : génération en javascript d'objets défilants, texte et/ou images, mode horizontal ou vertical.
ABCIWEB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/03/2011, 23h37   #13
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par ABCIWEB Voir le message
ça le fait sur toutes les images que tu envoies ? Sinon ça pourrait peut-être venir du fait qu'une image est corrompue
Oui, ça le fait à chaque fois, d’ailleurs il suffit d'essayer le code, je suis persuadé que ça fera la même.
Dans un éditeur hexadécimal, j'ai comparé une image transmise avec son original et il manque des octets par intermittence...

Je met les 2 photos dès fois que ça peut aider à trouver le problème...
photo local
photo serveur
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 00h27   #14
Modérateur
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 16 191
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 16 191
Points : 25 347
Points : 25 347
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
La première modification que je trouve entre les deux fichiers, c'est une séquence 18 0D 0D 18 (offset 244 du fichier) qui deviens subitement 18 0D 18
Disparition d'un retour à la ligne! Il dois y avoir un bout de code, soit dans ton php, soit dans ton java (va trouver lequel.....) qui lit le fichier comme étant un fichier texte et non pas une fichier binaire, et interprète ces carriage return!

D'après la doc php, d'ailleurs:

Citation:
Exemple #2 Exemple avec fread() et un fichier binaire
Avertissement

Sur les systèmes qui différencient les fichiers textes et binaires (i.e. Windows) le fichier doit être ouvert avec la lettre 'b' ajoutée au paramètre de mode de la fonction fopen().
Hors ton code d'exemple n'utilise pas ce 'b'
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
"Votre génitrice tute des pédoncules au pandémonium" (le conjurateur, 1973)
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 00h32   #15
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par tchize_ Voir le message
La première modification que je trouve entre les deux fichiers, c'est une séquence 18 0D 0D 18 (offset 244 du fichier) qui deviens subitement 18 0D 18
Disparition d'un retour à la ligne! Il dois y avoir un bout de code, soit dans ton php, soit dans ton java (va trouver lequel.....) qui lit le fichier comme étant un fichier texte et non pas une fichier binaire, et interprète ces carriage return!
Merci pour l'info, je n'aurais pas remarqué cette subtilité.
Je sais ou chercher, dans la config du client HTTP.
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 00h35   #16
Modérateur
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 16 191
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 16 191
Points : 25 347
Points : 25 347
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
il y a aussi ceci dans la doc php

Citation:
Note:

Pour des raisons de portabilité, il est recommandé de toujours utiliser l'option 'b' lorsque vous ouvrez des fichiers avec fopen().
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
"Votre génitrice tute des pédoncules au pandémonium" (le conjurateur, 1973)
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 01h15   #17
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par tchize_ Voir le message
il y a aussi ceci dans la doc php
Moi je veux bien, mais en utilisant move_uploaded_file on ne maîtrise pas grand chose...
Mais je vais tester avec PUT pour voir.

Edit:
Ça ne donne rien en ajoutant "b", en lecture et en écriture avec PUT...
dawadam est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 04h17   #18
Membre Expert
 
Inscription : septembre 2010
Messages : 1 242
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 1 242
Points : 1 564
Points : 1 564
J'ai essayé d'uploader ta photo locale avec cette classe de téléchargement php:
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
<?php
 
class Telechargement
{
 
private $index_ses = 'Verif-Up=Wxz';
private $reload_page = false;
private $extensions_autorisees = null;
private $ses_mes;
private $ses_vis;
private $ses_etat;
private $index_mes;
private $index_etat;
private $repertoire;
private $renomme = false;
private $mode_renommage_incr = false;
private $controle_fichier = false;
private $controle_img = false;
private $verif_ext;
private $file_form;
private $verif_post;
private $verif_get;
private $adresse_repertoire;
private $dim_image_source = null;
private $nouveau_nom = null;
private $nouveau_nom_ext = null;
 
private $redimension = array();
private $qualite = 88;
 
private $tab_mes = array(
'Le poids total maximum du formulaire autorisé par le serveur est dépassé',
'téléchargé dans le dossier',
'renommé',
'problème lors du transfert du fichier',
'extension non autorisée. Extensions autorisées :',
'non valide. Veuillez renommer votre fichier avant le téléchargement',
'ce fichier existe déjà',
'n\'est pas une image valide. Types de fichiers autorisés : gif, jpg, jpeg, png',
'excède la taille maximale de fichier autorisée par le serveur',
'excède la taille maximale de fichiers autorisée dans le formulaire',
'non téléchargé. Problème lors du téléchargement vers le serveur',
'a une résolution trop importante pour être traité. Envoyez un fichier avec une résolution inférieure',
'problème lors de la création de l\'image intermédiaire. Fichier non traité',
'problème lors du redimensionnement',
'problème lors du transfert du fichier redimensionné',
'redimensionné en',
'optimisé en',
'nom de destination du fichier non valide',
'téléchargement OK'
);
 
public function __construct ($repertoire = null, $verif_post = null, $file_form = null, $verif_get = null, $tab_message = null)
{      
        if (!session_id()) session_start();
 
 
        $this->repertoire = trim($repertoire);
        $this->verif_post = trim($verif_post);
        $this->file_form = trim($file_form);
        $this->verif_get = trim($verif_get);
 
        $this->Verif_param();
        $this->Verif_repertoire($this->repertoire);
 
        $this->index_mes = $this->verif_post.' '.$this->file_form.'mes';                      
        $this->index_etat = $this->verif_post.' '.$this->file_form;
 
        $this->ses_mes[$this->index_mes] =& $_SESSION[$this->index_ses][$this->index_mes];
        $this->ses_etat[$this->index_etat] =& $_SESSION[$this->index_ses][$this->index_etat];
 
        if (isset($tab_message)) $this->Set_Tab_messages($tab_message);
 
        $this->Verif_max_post();
 
}
 
// FONCTIONS DE CONTROLE DES DONNEES WEBMESTRE
private function Verif_param ()
{
        try
                {
                        if(empty($this->repertoire) || empty($this->verif_post) || empty($this->file_form))
 
                        throw new Exception('Les trois premiers paramètres de la classe de téléchargement de fichiers, correspondant :<br /><br />- 1/ Au nom du répertoire de destination  <br />- 2/ Au nom du champ $_POST de contrôle d\'envoi du formulaire  <br />- 3/ Au nom du champ $_FILES du formulaire<br /><br /> DOIVENT ETRE REMPLIS<br />');                                          
                }
 
        catch(Exception $e)
 
                {
                        echo $e->getMessage ();
                        exit;
                }      
}                         
private function Verif_repertoire ($rep)
{                              
        try
                {                                                              
                        if (!is_dir($this->Adresse_repertoire($rep)))
                                {
                                        throw new Exception('- Chemin du dossier de destination "'.$this->Adresse_repertoire($rep).'" NON VALIDE');
                                }
 
                        if (!is_writable($this->Adresse_repertoire($rep)))                  
                                {
                                        throw new Exception('- Chemin du dossier de destination "'.$this->Adresse_repertoire($rep).'" NON ACCESSIBLE EN ECRITURE');
                                }
 
                }
 
        catch(Exception $e)
 
                {
                        echo $e->getMessage();
                        exit;
                }
 
}              
 
private function Verif_tab_extension ()
{            
        try
                {
                        if(is_array($this->extensions_autorisees))                                                    
                                {
                                        if(count($this->extensions_autorisees) > 0)  
 
                                                $this->verif_ext = true;
                                                else
                                                $this->verif_ext = false;
                                }                  
                                else if ($this->controle_img === false && count($this->redimension) == 0)
                                {
                                        throw new Exception("Par sécurité, vous devez employer la fonction \"Set_Extensions_accepte\" pour envoyer un tableau d'extensions autorisées après l'initialisation de la classe et avant l'utilisation de la fonction d'upload, excepté si vous employez la fonction \"Set_Controle_dimImg\" qui contrôle des images de type gif, jpg, jpeg ou png, ou si vous employez la fonction \"Set_Redim\" de redimensionnement des images qui effectue ces mêmes contrôles.<br /><br />Alternativement, si vous ne souhaitez pas vérifier l'extension des fichiers, envoyez un tableau vide.");            
                                }
                }
 
        catch(Exception $e)
 
                {
                        echo $e->getMessage();
                        exit;
                }
}
 
private function Verif_tab_messages ($tab)
{                              
        try
                {                                                              
                        if (!is_array($tab))
                                {
                                        throw new Exception('- Le tableau des messages envoyé en paramètre n\'est pas un tableau valide. Il doit correspondre au tableau suivant : <br >');
                                }
 
                        if (count($tab) != count($this->tab_mes))                  
                                {
                                        throw new Exception('- Le tableau des messages envoyé en paramètre n\'a pas le nombre d\'éléments nécessaire (= '.count($this->tab_mes).') correspondant aux libellés suivants : <br >');
                                }
 
                }
 
        catch(Exception $e)
 
                {
                        echo $e->getMessage();
                        echo '<pre>';
                        print_r($this->tab_mes);
                        echo '</pre>';
                        exit;
                }
 
}              
 
private function Verif_nouveau_nom ($nom, $param = null)
{                              
        try
                {                                                              
                        $nom_fichier = $this->Nettoie_nom_fichier($nom);
 
                        if($nom_fichier === false)
                                {
                                        throw new Exception('- Le nom de fichier "'.$nom.'" envoyé en paramètre à la fonction "Set_Nomme_fichier" n\'est pas un nom de fichier valide.');
                                }      
 
                        if($nom_fichier !== $nom)
                                {
                                        throw new Exception('- Le nom de fichier "'.$nom.'" envoyé en paramètre à la fonction "Set_Nomme_fichier" n\'est pas un nom de fichier valide. Suggestion possible : "'.$nom_fichier.'"');
                                }                                                                                          
                }
 
        catch(Exception $e)
 
                {
                        if (empty($param))
                                {
                                        echo $e->getMessage();
                                        exit;
                                }
                                else
                                {
                                        if (!empty($this->tab_mes[17])) $this->Set_message('', '', '"'.$nom.'" : '.$this->tab_mes[17]);
                                        $this->nouveau_nom = false;
                                }
                }
 
}              
 
// FONCTIONS PUBLIQUES        
public function Set_Extensions_accepte ($extensions_autorisees)
{
        $this->extensions_autorisees = $extensions_autorisees;
}
 
public function Set_Renomme_fichier($incr = null)
{
        if (isset($incr) && trim($incr) != '') $this->mode_renommage_incr = true;
 
        $this->renomme = true;
}
 
public function Set_Nomme_fichier($nom = null, $extension = null, $param = null)
{
        $nom = trim($nom);
        $param = trim($param);
 
        $this->Verif_nouveau_nom($nom,$param);
 
        $this->nouveau_nom = isset($this->nouveau_nom)? $this->nouveau_nom : $nom;
 
        if(isset($extension) && trim($extension) != '') $this->nouveau_nom_ext = true;
}
 
public function Set_Controle_fichier()
{
        $this->controle_fichier = true;
}
 
public function Set_Controle_dimImg ()
{
        $this->controle_img = true;
}
 
public function Get_Tab_message ()
{
        if (isset($this->ses_mes[$this->index_mes]))
                {
                        $tab_result = $this->ses_mes[$this->index_mes];
 
                        $this->ses_mes[$this->index_mes] = null;
 
                        return $tab_result;
                }
 
                else return array();                          
}
 
public function Get_Tab_upload ()
{  
        if (isset($this->ses_etat[$this->index_etat]))
 
                {
                        $tab_result = array();
 
                        $infos_formulaire = explode(' ',$this->index_etat);
 
                        $tab_result['identifiant'] = $infos_formulaire[0];
 
                        $tab_result['champ'] = isset($infos_formulaire[1])? $infos_formulaire[1] : '';
 
                        $tab_result['resultat'] = array();
 
                        foreach($this->ses_etat[$this->index_etat] as $num => $rep)
                                {                                          
                                        foreach ($rep as $key => $value)      
                                                {
                                                        $infos_fichier = explode(' ',$value);
 
                                                        $tab_result['resultat'][$num][$key]['nom'] = $infos_fichier[0];
                                                        $tab_result['resultat'][$num][$key]['dim'] = isset($infos_fichier[1])? $infos_fichier[1] : '';        
                                                }
                                }
 
                        $this->ses_etat[$this->index_etat] = null;
 
                        return $tab_result;
                }
 
                else return array();
}      
 
public function Get_Reload_page ()
{
        header("Location:".$_SERVER['PHP_SELF']);
        exit;  
}      
 
public function Return_Octets($val)
{
        $val = trim($val);
        $last = strtolower($val[strlen($val)-1]);
 
        switch($last)
                        {
                                case 'g':  $val *= 1024;
                                case 'm': $val *= 1024;
                                case 'k':  $val *= 1024;
                        }
 
        return $val;
}
 
public function Set_Redim ($largeur_max = null, $hauteur_max = null, $rep_redim = null, $qualite = null, $limit_redim = null)
{
 
        $rep_redim = !empty($rep_redim) && trim($rep_redim) != '' ? trim($rep_redim) : $this->repertoire;
 
        if($rep_redim != $this->repertoire) $this->Verif_repertoire($rep_redim);
 
 
        $largeur_max =  isset($largeur_max) && trim($largeur_max) != '' ? trim($largeur_max) : null;
        $this->redimension[$rep_redim]['L_max'] = is_numeric($largeur_max) && !empty($largeur_max) ? abs(intval($largeur_max)) : null;
 
        $hauteur_max = !empty($hauteur_max) && trim($hauteur_max) != '' ? trim($hauteur_max) : null;
        $this->redimension[$rep_redim]['H_max'] = is_numeric($hauteur_max) && !empty($hauteur_max) ? abs(intval($hauteur_max)) : null;
 
        $qualite = !empty($qualite) && trim($qualite) != '' ? trim($qualite) : null;
        $this->redimension[$rep_redim]['Qualite'] = is_numeric($qualite) && intval($qualite) > 0 && intval($qualite) < 101 ? intval($qualite) : $this->qualite;
 
        $this->redimension[$rep_redim]['Limit_redim'] = isset($limit_redim) && trim($limit_redim) != '' ? false : true;        
 
}
 
public function Set_Tab_messages ($tab = null)
{
        $this->Verif_tab_messages($tab);
 
        $this->tab_mes = array_map('trim',$tab);
}
 
public function Upload ($reload = null)
{
        if (!empty($reload)) $this->reload_page = true;
 
        $this->Upload_Liste();
}             
 
// FONCTION UPLOAD : Liste (dans le cas d'un tableau) le champ spécifié de type $_FILES et envoie le résultat à la fonction Upload_fichier puis effectue ou non un reload
private function Upload_Liste ($reload = null)
{              
        $this->Verif_tab_extension();
 
        if (isset($_POST[$this->verif_post],$_FILES[$this->file_form]))
                {                      
                        $localfile = $_FILES[$this->file_form]['name'];
                       if (is_array($localfile))
                                {      
                                        foreach ($localfile as $index_champ => $nom_fichier)
                                                {
                                                        $nom_local = $_FILES[$this->file_form]['name'][$index_champ];
                                                        $nom_temp = $_FILES[$this->file_form]['tmp_name'][$index_champ];
                                                        $erreur = $_FILES[$this->file_form]['error'][$index_champ];    
 
                                                        $this->Upload_fichier ($index_champ,$nom_local,$nom_temp,$erreur);
                                                }                                                                                                                         
                                 }                                
                                 else                                      
                                 {
                                        $nom_local = $_FILES[$this->file_form]['name'];
                                        $nom_temp = $_FILES[$this->file_form]['tmp_name'];
                                        $erreur = $_FILES[$this->file_form]['error'];
 
                                        $this->Upload_fichier (0,$nom_local,$nom_temp,$erreur);
                                }
 
                        if ($this->reload_page === true) $this->Get_Reload_page();                                                                                            
                }            
}
 
// FONCTION UPLOAD FICHIER          
private function Upload_fichier ($index_champ, $nom_local, $nom_temp, $erreur)
{  
 
        $adresse_fichier = $this->Verif_upload_fichier($index_champ, $nom_local, $nom_temp, $erreur);
 
        if ($adresse_fichier === false) return false;
 
        if ($this->renomme === true) $adresse_fichier = $this->Rename_fich($adresse_fichier);
 
 
        if (count($this->redimension) > 0)
                {
                        $redim = $this->Redim_liste ($index_champ, $nom_local, $nom_temp, $adresse_fichier);
 
                        if($redim === false) return false;
 
 
                        if (array_key_exists($this->repertoire,$this->redimension)) return false;
                }
 
 
        if (@move_uploaded_file($nom_temp, $adresse_fichier))
                {
                        $nom_fichier = basename($adresse_fichier);
 
                        $resultat1 = !empty($this->tab_mes[1]) ? '"'.$nom_local.'" '.$this->tab_mes[1].' "'.$this->repertoire.'"' : null;
                        $resultat2 = !empty($this->tab_mes[1]) && !empty($this->tab_mes[2]) ? '"'.$nom_local.'" '.$this->tab_mes[2].' "'.$nom_fichier.'" '.$this->tab_mes[1].' "'.$this->repertoire.'"' : null;
 
                        $resultat = $nom_local === $nom_fichier ?  $resultat1 : $resultat2;
 
                        if (isset($resultat))
                        $this->Set_message ($this->repertoire, $index_champ, $resultat);
                        else
                        $this->Set_message ($this->repertoire, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[18]);
 
                        if (($this->controle_img === true || count($this->redimension) > 0) && isset($this->dim_image_source))
 
                                {
                                        $dim = implode('x',$this->dim_image_source);
 
                                        $this->Set_result ($this->repertoire, $index_champ, $nom_fichier.' '.$dim);
                                }                                                                      
                                else                                                  
                                        $this->Set_result ($this->repertoire, $index_champ, $nom_fichier);
 
                }                          
                else      
                {
                        if (!empty($this->tab_mes[3])) $this->Set_message ($this->repertoire, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[3]);
                        $this->Set_result ($this->repertoire, $index_champ, false);
 
                        @unlink($nom_temp);
                }                                                            
 
}
 
// FONCTION VERIF UPLOAD FICHIER
private function Verif_upload_fichier ($index_champ, $nom_local, $nom_temp, $erreur)
{  
        // Si $erreur != 0 problème lors de l'upload ou champ vide (=4)      
        if ($erreur !== 0)                    
                {
                        if ($erreur != 4)
                                {
                                        if ($this->Files_erreur($erreur,$nom_local) != null) $this->Set_message ($this->repertoire, $index_champ, $this->Files_erreur($erreur,$nom_local));
                                }
 
                        $this->Set_result ($this->repertoire, $index_champ, false);
 
                        return false;
                }                  
 
 
        // Si le témoin de vérification "$this->verif_ext" sur les extensions retourne true
        if ($this->verif_ext === true)                                                  
                {
                         if ($this->Verif_extension($nom_local) === false)
                                {
                                        $liste_extensions = implode(', ',$this->extensions_autorisees);
 
                                        if (!empty($this->tab_mes[4])) $this->Set_message ($this->repertoire, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[4].' '.$liste_extensions);
 
                                        $this->Set_result ($this->repertoire, $index_champ, false);
 
                                        return false;                                      
                                 }      
                }
 
 
        //Si nouveau_nom et nouveau_nom_ext définis -> nouveau_nom prend l'extension du fichier téléchargé
        if (isset($this->nouveau_nom) && $this->nouveau_nom !== false)
                {
                        $nom_fichier = isset($this->nouveau_nom_ext)? $this->nouveau_nom.'.'. strtolower(substr($nom_local,strrpos($nom_local, ".")+1)) : $this->nouveau_nom;
                }        
 
        // Nettoyage du nom de fichier pour avoir un nom de fichier valide sur le serveur
        if(!isset($this->nouveau_nom)) $nom_fichier = $this->Nettoie_nom_fichier($nom_local);
 
        if ($nom_fichier === false || $this->nouveau_nom === false)
                {
                        if (isset($this->nouveau_nom))
 
                                return false;
 
                                else
                                        {
                                                if (!empty($this->tab_mes[5])) $this->Set_message ($this->repertoire, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[5]);
 
                                                $this->Set_result ($this->repertoire, $index_champ, false);
 
                                                return false;
                                        }
                 }
 
        // Si l'on a employé la fonction "Set_Controle_fichier"                                
        if ($this->controle_fichier === true)
                {
                        if (is_file($this->Adresse_repertoire($this->repertoire).$nom_fichier))
                                {
                                        $nom = isset($this->nouveau_nom)? $this->nouveau_nom : $nom_local;
 
                                        if (!empty($this->tab_mes[6])) $this->Set_message ($this->repertoire, $index_champ, '"'.$nom.'" '.$this->tab_mes[6]);
 
                                        $this->Set_result ($this->repertoire, $index_champ, false);
 
                                        return false;
                                }                      
                }
 
        // Si l'on a employé la fonction "Set_Controle_dimImg"
        if ($this->controle_img === true && count($this->redimension) == 0)
                {
                        $this->dim_image_source = null;
 
                        $infos_images = $this->Infos_image($nom_temp);
 
                        if ($infos_images === false)
                                {                                                      
                                        if (!empty($this->tab_mes[7])) $this->Set_message ($this->repertoire, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[7]);
                                        $this->Set_result ($this->repertoire, $index_champ, false);
 
                                        return false;
                                }
                                else
                                {
                                        $this->dim_image_source = array_slice($infos_images, 0, 2);
                                }
                }
       // Si on arrive ici c'est que tout c'est bien passé et l'on retourne l'adresse de destination du fichier
        return $this->Adresse_repertoire($this->repertoire).$nom_fichier;                                                                                                                                                                                                                                                      
}                       
private function Set_message ($repertoire = null, $index = null, $message)
{
        if (isset($index))
 
        $this->ses_mes[$this->index_mes][$index][$repertoire] = $message;
 
        else
 
        $this->ses_mes[$this->index_mes][] = $message;
}
 
private function Set_result ($repertoire = null, $index, $message)
{              
        $this->ses_etat[$this->index_etat][$index][$repertoire] = $message;
}
 
private function Verif_extension ($fichier)
{
        $extension = strtolower(substr($fichier,strrpos($fichier, ".")+1));
 
        if (in_array($extension,$this->extensions_autorisees))
 
        return true;
        else
        return false;                  
}
 
private function Verif_max_post()
{                                                  
        if (isset($_GET[$this->verif_get]) && empty($_POST[$this->verif_post]))
                {
                        if (!empty($this->tab_mes[0])) $this->Set_message ('', '', $this->tab_mes[0]);
 
                        $this->Get_Reload_page ();                      
                }
}
 
private function Adresse_racine()
{
        $adresse_racine = (substr($_SERVER['DOCUMENT_ROOT'],-1) == '/')? $_SERVER['DOCUMENT_ROOT'] : $_SERVER['DOCUMENT_ROOT'].'/' ;
 
        return $adresse_racine;
}              
 
private function Adresse_repertoire($rep)
{
        return $this->Adresse_racine().$rep.'/';
}
 
private function Nettoie_nom_fichier($nom_fichier)
{
        $cible = array(
        'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', '&#258;', '&#260;',
        'Ç', '&#262;', '&#268;', 'Œ',
        '&#270;', '&#272;',
        'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', '&#259;', '&#261;',
        'ç', '&#263;', '&#269;', 'œ',
        '&#271;', '&#273;',
        'È', 'É', 'Ê', 'Ë', '&#280;', '&#282;',
        '&#286;',
        'Ì', 'Í', 'Î', 'Ï', '&#304;',
        '&#313;', '&#317;', '&#321;',
        'è', 'é', 'ê', 'ë', '&#281;', '&#283;',
        '&#287;',
        'ì', 'í', 'î', 'ï', '&#305;',
        '&#314;', '&#318;', '&#322;',
        'Ñ', '&#323;', '&#327;',
        'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', '&#336;',
        '&#340;', '&#344;',
        '&#346;', '&#350;', 'Š',
        'ñ', '&#324;', '&#328;',
        'ò', 'ó', 'ô', 'ö', 'ø', '&#337;',
        '&#341;', '&#345;',
        '&#347;', '&#351;', 'š',
        '&#354;', '&#356;',
        'Ù', 'Ú', 'Û', '&#370;', 'Ü', '&#366;', '&#368;',
        'Ý', 'ß',
        '&#377;', '&#379;', 'Ž',
        '&#355;', '&#357;',
        'ù', 'ú', 'û', '&#371;', 'ü', '&#367;', '&#369;',
        'ý', 'ÿ',
        '&#378;', '&#380;', 'ž',
        '&#1040;', '&#1041;', '&#1042;', '&#1043;', '&#1044;', '&#1045;', '&#1025;', '&#1046;', '&#1047;', '&#1048;', '&#1049;', '&#1050;', '&#1051;', '&#1052;', '&#1053;', '&#1054;', '&#1055;', '&#1056;',
        '&#1072;', '&#1073;', '&#1074;', '&#1075;', '&#1076;', '&#1077;', '&#1105;', '&#1078;', '&#1079;', '&#1080;', '&#1081;', '&#1082;', '&#1083;', '&#1084;', '&#1085;', '&#1086;', '&#1088;',
        '&#1057;', '&#1058;', '&#1059;', '&#1060;', '&#1061;', '&#1062;', '&#1063;', '&#1064;', '&#1065;', '&#1066;', '&#1067;', '&#1068;', '&#1069;', '&#1070;', '&#1071;',
        '&#1089;', '&#1090;', '&#1091;', '&#1092;', '&#1093;', '&#1094;', '&#1095;', '&#1096;', '&#1097;', '&#1098;', '&#1099;', '&#1100;', '&#1101;', '&#1102;', '&#1103;'
        );
 
        $rempl = array(
        'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'A', 'A',
        'C', 'C', 'C', 'CE',
        'D', 'D',
        'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'a', 'a',
        'c', 'c', 'c', 'ce',
        'd', 'd',
        'E', 'E', 'E', 'E', 'E', 'E',
        'G',
        'I', 'I', 'I', 'I', 'I',
        'L', 'L', 'L',
        'e', 'e', 'e', 'e', 'e', 'e',
        'g',
        'i', 'i', 'i', 'i', 'i',
        'l', 'l', 'l',
        'N', 'N', 'N',
        'O', 'O', 'O', 'O', 'O', 'O', 'O',
        'R', 'R',
        'S', 'S', 'S',
        'n', 'n', 'n',
        'o', 'o', 'o', 'o', 'o', 'o',
        'r', 'r',
        's', 's', 's',
        'T', 'T',
        'U', 'U', 'U', 'U', 'U', 'U', 'U',
        'Y', 'Y',
        'Z', 'Z', 'Z',
        't', 't',
        'u', 'u', 'u', 'u', 'u', 'u', 'u',
        'y', 'y',
        'z', 'z', 'z',
        'A', 'B', 'B', 'r', 'A', 'E', 'E', 'X', '3', 'N', 'N', 'K', 'N', 'M', 'H', 'O', 'N', 'P',
        'a', 'b', 'b', 'r', 'a', 'e', 'e', 'x', '3', 'n', 'n', 'k', 'n', 'm', 'h', 'o', 'p',
        'C', 'T', 'Y', 'O', 'X', 'U', 'u', 'W', 'W', 'b', 'b', 'b', 'E', 'O', 'R',
        'c', 't', 'y', 'o', 'x', 'u', 'u', 'w', 'w', 'b', 'b', 'b', 'e', 'o', 'r'
        );
 
        $nom_fichier = str_replace($cible, $rempl, $nom_fichier);
 
        $nom_fichier = preg_replace('#[^.a-z0-9_-]+#i', '', $nom_fichier);
 
        if (trim($nom_fichier) != '')
 
        return $nom_fichier;
        else
        return false;
}
 
private function Rename_fich($adresse_fichier)
{
        if (is_file($adresse_fichier))
                {
                        $info = pathinfo($adresse_fichier);
                        $extension = isset($info['extension'])? '.'.$info['extension'] : null;
                        $dossier = $info['dirname'];
                        $basename = $info['basename'];
 
                        $filename = isset($extension) && strrpos($basename,$extension) !== false ? substr($basename,0,strrpos($basename,$extension)) : $basename;
 
                        if ($this->mode_renommage_incr === true)
                                {
                                        $file = $filename.'_';
                                        $file = addcslashes($file,'.');
 
                                        $ext = isset($extension) ? addcslashes($extension,'.') : null;
 
                                        $match = isset($extension)? '#'.$file.'[0-9]+'.$ext.'#' : '#'.$file.'[0-9]+$#';
 
                                        $tab_identique = array();
 
                                        if(class_exists('RegexIterator'))
                                                {
                                                        $files = new RegexIterator(new DirectoryIterator($dossier),$match);
                                                        foreach ($files as $fileinfo) $tab_identique[] = $fileinfo->getFilename();
                                                }      
                                                else
                                                {      
                                                        $files = new DirectoryIterator($dossier);                      
                                                        foreach ($files as $fileinfo) if (preg_match($match,$fileinfo->getFilename())) $tab_identique[] = $fileinfo->getFilename();    
                                                }
 
                                        natsort($tab_identique);
 
                                        $dernier = array_pop($tab_identique);
 
                                        unset($tab_identique);
 
 
                                        $dernier = isset($dernier)? basename($dernier,$extension) : '';                                                                                                                                                                                                                                                                                
 
                                        $file = preg_replace_callback('#([0-9]+$)#', create_function('$matches','return $matches[1]+1;'), $dernier, '1', $count);
 
                                        $filename = !empty($count)? $file : $filename.'_1';
 
                                }
                                else
                                {
                                        $filename .= '_'.uniqid();
                                }
 
                        $filename = !empty($extension) ? $filename.$extension : $filename;
 
 
                        $adresse = $dossier.'/'.$filename;
 
                        if (!is_file($adresse)) return $adresse;
                        else                                                                                                                                                                                                                                   
                        return $this->Rename_fich($adresse_fichier);                        
        }
 
        else
        {
                return $adresse_fichier;
        }
}
 
private function Files_erreur ($file_error, $nom_fichier)
{
        $message = null;
 
        switch ($file_error)
                {
                        case "1" : $message = !empty($this->tab_mes[8]) ? '"'.$nom_fichier.'" '.$this->tab_mes[8] : null; break;
                        case "2" : $message = !empty($this->tab_mes[9]) ? '"'.$nom_fichier.'" '.$this->tab_mes[9] : null; break;
                        case "3" :
                        case "4" :
                        case "6" :
                        case "7" :
                        case "8" : $message = !empty($this->tab_mes[10]) ? '"'.$nom_fichier.'" '.$this->tab_mes[10] : null; break;
                }          
 
        return $message;
}
 
private function Enoughmem ($x, $y, $max_mem, $rgb = 3)
{      
        if (function_exists('memory_get_usage'))
                {
                        //http://www.php.net/manual/fr/function.imagecreatetruecolor.php#99623
                        return ( $x * $y * $rgb * 1.7 < $max_mem - memory_get_usage() );
                }
        else return true;
}
 
private function Infos_image ($fich)
{
        $types_accepte = array(1,2,3);
 
        $infos = @getimagesize($fich);    
 
        if (!empty($infos[0]) && !empty($infos[1]) && !empty($infos[2]) && in_array($infos[2],$types_accepte))
 
        return array($infos[0], $infos[1], $infos[2], $infos['bits'], $infos['channels']);                
        else      
        return false;
}
private function Redim_liste ($index_champ, $nom_local, $nom_temp, $adresse_fichier)
{                              
 
        $info_image = $this->Infos_image ($nom_temp);
 
        $this->dim_image_source = null;
 
 
        if ($info_image === false)            
        {
                if (!empty($this->tab_mes[7])) $this->Set_message ($this->repertoire, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[7]);
                $this->Set_result ($this->repertoire, $index_champ, false);
 
                return false;
        }
        else
        {
                $this->dim_image_source = array_slice($info_image, 0, 2);
        }      
 
 
        $dim_max = true;
 
        if ($info_image[2] == 2)              
        {                      
                $m_limit = ini_get('memory_limit');
                $m_limit = $this->Return_Octets($m_limit);
 
                if (!$this->Enoughmem($info_image[0],$info_image[1],$m_limit))
                        {
                                $dim_max = false;                                      
                        }
        }
 
        $nouvelle_image = $dim_max === true ? $this->Image_create ($nom_temp, $info_image[2]) : false;
 
 
        $nom_fichier = basename($adresse_fichier);
 
 
        foreach ($this->redimension as $rep => $value)
        {
 
                if($dim_max === false)
                        {
                                if (!empty($this->tab_mes[11])) $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[11]);
                                $this->Set_result ($rep, $index_champ, false);
 
                                break;
                        }
 
                if ($nouvelle_image === false && $dim_max === true)
                        {
                                if (!empty($this->tab_mes[12])) $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[12]);
 
                                $this->Set_result ($rep, $index_champ, false);
 
                                break;
                        }
 
                $largeur_max = $value['L_max'];
                $hauteur_max = $value['H_max'];
                $qualite = $value['Qualite'];
                $limit_redim = $value['Limit_redim'];                          
 
                $redimensionnement = true;
 
                if(empty ($largeur_max) && empty ($hauteur_max))
                        {
                                $largeur_destination = $info_image[0];
                                $hauteur_destination = $info_image[1];
                                $redimensionnement = false;
                        }
                        else          
                        {
                                $ratio_orig = $info_image[0]/$info_image[1];
 
                                if(!empty ($largeur_max) && empty ($hauteur_max))
                                        {                      
                                                $largeur_destination = intval ($largeur_max);
                                                $hauteur_destination = intval ($largeur_max/$ratio_orig);
                                        }
                                        else if (empty ($largeur_max) && !empty ($hauteur_max))
                                        {      
                                                $largeur_destination = intval ($hauteur_max*$ratio_orig);
                                                $hauteur_destination = intval ($hauteur_max);
                                        }
                                        else
                                        {
                                                $ratioh = $hauteur_max/$info_image[1];
                                                $ratiow = $largeur_max/$info_image[0];
                                                $ratio = min($ratioh, $ratiow);
 
                                                $largeur_destination = intval ($ratio*$info_image[0]);
                                                $hauteur_destination  = intval ($ratio*$info_image[1]);        
                                        }
 
 
                        if(($largeur_destination > $info_image[0] || $hauteur_destination > $info_image[1]) && $limit_redim === true)
                                        {
                                                $largeur_destination = $info_image[0];
                                                $hauteur_destination = $info_image[1];
                                                $redimensionnement = false;
                                        }      
                        }
 
 
                if ($redimensionnement && $nouvelle_image !== false)
                        {    
                                $dim_desti = true;
 
                                if ($info_image[2] == 2)              
                                        {
                                                if (!$this->Enoughmem($largeur_destination,$hauteur_destination,$m_limit))
                                                $dim_desti = false;
                                        }
 
 
                                $ressource = $dim_desti == true ? @imagecreatetruecolor ($largeur_destination, $hauteur_destination) : false;
 
                                if (!is_resource ($ressource))
                                        {
                                                if (!empty($this->tab_mes[11])) $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[11]);
 
                                                $this->Set_result ($rep, $index_champ, false);
 
                                                break;
                                        }
 
 
                                $redimensionnement = @imagecopyresampled ($ressource, $nouvelle_image, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $info_image[0], $info_image[1]);
 
                                if ($redimensionnement == false)
                                        {
                                                if (!empty($this->tab_mes[13])) $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[13]);
 
                                                $this->Set_result ($rep, $index_champ, false);
 
                                                break;
                                        }
 
 
                                $envoi = $this->Envoi_image ($ressource, $this->Adresse_repertoire($rep).$nom_fichier, $info_image[2], $qualite);
 
 
                                @imagedestroy($ressource);
 
 
                                if ($envoi === false)
                                        {
                                                if (!empty($this->tab_mes[14])) $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[14]);
 
                                                $this->Set_result ($rep, $index_champ, false);
 
                                                break;
                                        }
 
                                        else
 
                                        {                                              
                                                $resultat1 = !empty($this->tab_mes[15]) && !empty($this->tab_mes[1]) ? '"'.$nom_fichier.'" '.$this->tab_mes[15].' '.$largeur_destination.'x'.$hauteur_destination.' '.$this->tab_mes[1].' '.$rep.'' : null;
 
                                                $resultat2 = !empty($this->tab_mes[15]) && !empty($this->tab_mes[1]) && !empty($this->tab_mes[2]) ? '"'.$nom_local.'" '.$this->tab_mes[2].' "'.$nom_fichier.'" '.$this->tab_mes[15].' '.$largeur_destination.'x'.$hauteur_destination.' '.$this->tab_mes[1].' '.$rep.'' : null;
 
                                                $resultat = $nom_local === $nom_fichier ?  $resultat1 : $resultat2;
 
                                                if (isset($resultat))
                                                $this->Set_message ($rep, $index_champ, $resultat);
                                                else
                                                $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[18]);
 
 
                                                $dim = $largeur_destination.'x'.$hauteur_destination;
 
                                                $this->Set_result ($rep, $index_champ, $nom_fichier.' '.$dim);
                                        }
 
                        }
 
                        else if ($nouvelle_image !== false)
 
                        {
 
                                $envoi = $this->Envoi_image ($nouvelle_image, $this->Adresse_repertoire($rep).$nom_fichier, $info_image[2], $qualite);
 
                                if ($envoi === false)
                                        {
                                                if (!empty($this->tab_mes[3])) $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[3]);
 
                                                $this->Set_result ($rep, $index_champ, false);
 
                                                break;
                                        }
                                        else
                                        {
                                                $resultat1 = !empty($this->tab_mes[16]) && !empty($this->tab_mes[1]) ? '"'.$nom_fichier.'" '.$this->tab_mes[16].' '.$largeur_destination.'x'.$hauteur_destination.' '.$this->tab_mes[1].' '.$rep.'' : null;
 
                                                $resultat2 = !empty($this->tab_mes[16]) && !empty($this->tab_mes[1]) && !empty($this->tab_mes[2]) ? '"'.$nom_local.'" '.$this->tab_mes[2].' "'.$nom_fichier.'" '.$this->tab_mes[16].' '.$largeur_destination.'x'.$hauteur_destination.' '.$this->tab_mes[1].' '.$rep.'' : null;
 
                                                $resultat = $nom_local === $nom_fichier ?  $resultat1 : $resultat2;
 
                                                if (isset($resultat))
                                                $this->Set_message ($rep, $index_champ, $resultat);
                                                else
                                                $this->Set_message ($rep, $index_champ, '"'.$nom_local.'" '.$this->tab_mes[18]);
 
 
                                                $dim = $largeur_destination.'x'.$hauteur_destination;
 
                                                $this->Set_result ($rep, $index_champ, $nom_fichier.' '.$dim);
                                        }
 
                        }
 
        }
 
        @imagedestroy($nouvelle_image);
}
 
 
private function Image_create($fich, $type)
{
        switch ($type)
                {
                        case "1" : $nouvelle_image = @imagecreatefromgif($fich); break;
                        case "2" : $nouvelle_image = @imagecreatefromjpeg($fich); break;
                        case "3" : $nouvelle_image = @imagecreatefrompng($fich); break;
 
                        default : $nouvelle_image = null;
                }
 
        if (is_resource($nouvelle_image))
 
        return $nouvelle_image;
        else
        return false;
}
 
private function Envoi_image($ressource, $destination, $type, $qualite)
{              
        switch ($type)
                {
                        case "1" : $envoi = @imagegif($ressource, $destination); break;
                        case "2" : $envoi = @imagejpeg($ressource, $destination, $qualite); break;
                        case "3" : $qualite = $qualite == 0 ? 1 : $qualite;
                                        $qualite = 10 - ceil($qualite/10);                          
                                        $envoi = @imagepng($ressource, $destination, $qualite); break;
 
                        default : $envoi = false;
                }
 
        if ($envoi != false)
 
        return true;  
        else
        return false;
}
 
}
//FIN DE CLASSE
?>
et comme prévu tout se passe bien... (testé en local et sur un serveur distant). Tu peux éventuellement tester cette classe qui sait afficher les messages d'erreurs lors du téléchargement... je doute que cela vienne de ton code php car effectivement avec le move_upload_file y'a rien de particulier à paramétrer, mais bon tu saurais au moins si php détecte une erreur ou pas.
Sinon tu peux utiliser ce lien pour l'adapter à ton code et voir les erreurs générées par php.
__________________
- Réalisations
- Interface graphique : génération en javascript d'objets défilants, texte et/ou images, mode horizontal ou vertical.
ABCIWEB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 09h34   #19
Modérateur
 
Avatar de tchize_
 
Homme
Responsable de service informatique
Inscription : avril 2007
Messages : 16 191
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 32
Localisation : Belgique

Informations professionnelles :
Activité : Responsable de service informatique
Secteur : Service public

Informations forums :
Inscription : avril 2007
Messages : 16 191
Points : 25 347
Points : 25 347
Envoyer un message via MSN à tchize_ Envoyer un message via Skype™ à tchize_
un expert du PHP pourrait nous dire si $_FILE['fichier']['size'] affiche la taille du fichier temporaire stocké sur le disque ou si, au contraire, il affiche la taille déclarée dans les header HTTP? ÇA permettrais de savoir quel coté est en cause. Parce que, de la même manière, je ne vois aucune erreur dans son code de lecture fichier coté java!
__________________
⥀⥁ Чиз faq java, cours java, javadoc. Pensez à et
"Votre génitrice tute des pédoncules au pandémonium" (le conjurateur, 1973)
tchize_ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 09h49   #20
Membre habitué
 
Inscription : septembre 2007
Messages : 272
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 272
Points : 145
Points : 145
Citation:
Envoyé par tchize_ Voir le message
un expert du PHP pourrait nous dire si $_FILE['fichier']['size'] affiche la taille du fichier temporaire stocké sur le disque ou si, au contraire, il affiche la taille déclarée dans les header HTTP? ÇA permettrais de savoir quel coté est en cause. Parce que, de la même manière, je ne vois aucune erreur dans son code de lecture fichier coté java!
En plus de ça, la lecture du fichier est là pour l’exemple, dans le cas réel, le tableau de byte[] est directement fournit par la Class de capture photo.
dawadam 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 22h32.


 
 
 
 
Partenaires

Hébergement Web