Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > Images > GD
GD Forum d'entraide pour l'extension GD permettant de manipuler des images en PHP. Avant de poster -> tutoriels GD
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 28/02/2011, 09h46   #1
Membre confirmé
 
Inscription : mars 2004
Messages : 1 187
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 1 187
Points : 233
Points : 233
Par défaut Message d'erreur sur un .JPG

Bonjourà tous,

voici le message d'erreur que j'ai obtenu en chargeant une image JPG sur mon site :

Code :
1
2
3
 
 
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: premature end of data segment in /home/example/public_html/crecli04.php on line 411
Voici la ligne concernée :

Code :
1
2
3
4
5
6
 
 
            if ($tableau[2] == 2){
                    $jpeg = true;
                    // on crée une image à partir de notre grande image à l'aide de la librairie GD
                    $src = imagecreatefromjpeg($dest_dossier.'/'.$dest_fichier);
et le code qui précède

Code :
1
2
3
 
 
       $tableau = @getimagesize($_FILES['up_photo']['tmp_name']);
Je n'avais jamais eu cette erreur auparavant..

Savez-vous d'où cela peut venir ?
sam01 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/02/2011, 10h09   #2
Membre chevronné
 
Avatar de micetf
 
Homme Fred
Professeur des Ecoles
Inscription : mai 2009
Messages : 503
Détails du profil
Informations personnelles :
Nom : Homme Fred
Localisation : France, Rhône (Rhône Alpes)

Informations professionnelles :
Activité : Professeur des Ecoles
Secteur : Enseignement

Informations forums :
Inscription : mai 2009
Messages : 503
Points : 701
Points : 701
Bonjour,
A priori, ton fichier image source n'est pas "propre", par conséquent la librairie GD arrête tout et te renvoie cet avertissement.
Pour passer outre, il faut modifier le php.ini et modifier la directive qui précise comment sont gérés ces avertissements :
Code :
gd.jpeg_ignore_warning = 1;
Cf. GOOGLE ==> "gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data" et 1er lien (www.tayo.fr)

Voire mieux : ICI qui préconise :
Code :
ini_set("gd.jpeg_ignore_warning", 1);
Sans avoir à modifier le php.ini.

Fred
micetf est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/02/2011, 17h17   #3
Membre confirmé
 
Inscription : mars 2004
Messages : 1 187
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 1 187
Points : 233
Points : 233
Bonjour et merci pour la réponse.

Si j'ai bien compris, ça va m'éviter le message d'erreur mais j'obtiendrai toujours une image noire...

Car suite à mon message d'erreur, le fichier à bien été uploadé sur le serveur mais l'image est toute noire...
sam01 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/02/2011, 17h34   #4
Membre Expert
 
Inscription : septembre 2010
Messages : 1 239
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 1 239
Points : 1 561
Points : 1 561
Renvoie une autre image, celle-ci est corrompue (comme dit plus haut).
__________________
- 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 28/02/2011, 23h20   #5
Membre confirmé
 
Inscription : mars 2004
Messages : 1 187
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 1 187
Points : 233
Points : 233
J'aimerais prévenir l'internaute que son image est corrompue et qu'il faut qu'il charge une autre image...
sam01 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/03/2011, 00h00   #6
Membre Expert
 
Inscription : septembre 2010
Messages : 1 239
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 1 239
Points : 1 561
Points : 1 561
L'exemple 1 du manuel. Cela dit tu pourrais aussi avoir un pb de mémoire insuffisante qui renverrait également false...

Il y a cette classe qui gère pas mal d'erreurs (mémoire insuffisante, erreur de chargement, dépassement du post_max_size etc.):
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
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
 
<?php
// DEBUT DE CLASSE UPLOAD abciweb.net version 2.0
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
?>

Dans ton cas le message retourné devrait être "problème lors de la création de l'image intermédiaire. Fichier non traité" mais tu peux personnaliser les messages.
__________________
- 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
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 14h07.


 
 
 
 
Partenaires

Hébergement Web