header('Content-type: application/pdf');
<?php session_start(); require('fpdf.php'); // classe étendue pour créer en-tête et pied de page class PDF extends FPDF { // en-tête function Header() { //Police Arial gras 15 $this->SetFont('Arial','B',14); //Décalage à droite $this->Cell(80); //Titre $this->Cell(30,10,'Mon joli fichier PDF',0,0,'C'); //Saut de ligne $this->Ln(20); } // pied de page function Footer() { //Positionnement à 1,5 cm du bas $this->SetY(-15); //Police Arial italique 8 $this->SetFont('Arial','I',8); //Numéro de page $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); } } // création du pdf $pdf=new PDF(); $pdf->SetAuthor('Un grand écrivain'); $pdf->SetTitle('Mon joli fichier'); $pdf->SetSubject('Un exemple de création de fichier PDF'); $pdf->SetCreator('fpdf_cybermonde_org'); $pdf->AliasNBPages(); $pdf->AddPage();
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<?php 002 //this class is not part of Resize and upload image class. 003 //this class is property of some one else. 004 //I get this from phpclasses.org but forget the name of author. 005 //sorry for that. 006 007 class Image { 008 var $FileName; 009 var $FileSize; 010 var $FileType; 011 var $AllowedExtentions = array ("image/png", "image/gif", "image/jpeg", "image/pjpeg", "image/jpg"); 012 var $newWidth = 100; // new width 013 var $newHeight = 100; //new height 014 var $TmpName; 015 var $PicDir; //store uploaded images 016 var $MaxFileSize = 2000000; //kbytes 017 var $ImageQuality = 100; // image compression (max value 100) 018 019 function Image($FileName) { 020 $this->FileName=$FileName; 021 } 022 023 function GetInfo() { 024 $out=' Upload success! 025 Name: '.$this->FileName.' 026 file size: '.$this->FileSize.' byte 027 file type: '.$this->FileType.' 028 PicDir . $this->FileName . '> '; 029 030 return $out; 031 } 032 033 034 function GetFileExtention ($FileName) { 035 if (in_array ($this->FileType, $this -> AllowedExtentions)) { 036 return true; 037 } else { 038 return false; 039 } 040 041 } 042 043 function ExistFile () { 044 $fileexist = $_SERVER['DOCUMENT_ROOT'] . 045 dirname($_SERVER['PHP_SELF']) . 046 '/' . $this->PicDir . 047 $this->FileName; 048 if (file_exists($fileexist)) { return true; } 049 } 050 051 function GetError ($error) { 052 053 switch ($error) { 054 case 0 : 055 return "Error: Invalid file type $this->FileType ! Allow type: .jpg, .jpeg, .gif, .png $this->FileName "; 056 break; 057 058 case 1 : 059 return "Error: File $this->FileSize is too large! You must upload 1000 MB file "; 060 break; 061 062 case 2 : 063 return "Error: Please, select a file for uploading! "; 064 break; 065 066 case 3 : 067 return "Error: File $this->FileName already exist! "; 068 break; 069 } 070 071 } 072 073 074 function Resize () { 075 // header('Content-Type: image/gif'); 076 if (empty ($this->TmpName)) {return $this -> GetError (2);} 077 else if ($this->FileSize > $this->MaxFileSize) {return $this -> GetError (1);} 078 else if ($this -> GetFileExtention ($this->FileName) == false) {return $this -> GetError (0);} 079 else if ($this -> ExistFile()) {return $this -> GetError (3);} 080 081 else { 082 083 $ext = explode(".",$this->FileName); 084 $ext = end($ext); 085 $ext = strtolower($ext); 086 087 // Get new sizes 088 list($width_orig, $height_orig) = getimagesize($this->TmpName); 089 090 $ratio_orig = $width_orig/$height_orig; 091 092 if ($this->newWidth/$this->newHeight > $ratio_orig) { 093 $this->newWidth = $this->newHeight*$ratio_orig; 094 } else { 095 $this->newHeight = $this->newWidth/$ratio_orig; 096 } 097 098 $normal = imagecreatetruecolor($this->newWidth, $this->newHeight); 099 100 if ($ext "jpg") { $source imagecreatefromjpeg($this->TmpName); } 101 else if ($ext "gif") { $source imagecreatefromgif ($this->TmpName); } 102 else if ($ext == "png") 103 { 104 $this->ImageQuality = 9; 105 $source = imagecreatefrompng ($this->TmpName); 106 } 107 108 imagecopyresampled($normal, $source, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $width_orig, $height_orig); 109 110 111 if ($ext == "jpg") { 112 //ob_start(); 113 imagejpeg($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); 114 //$binaryThumbnail = ob_get_contents(); 115 //ob_end_clean(); 116 } 117 else if ($ext == "gif") { imagegif ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); } 118 else if ($ext == "png") { imagepng ($normal, "$this->PicDir/$this->FileName", "$this->ImageQuality"); } 119 120 imagedestroy($source); 121 122 //echo $this -> GetInfo(); 123 124 } 125 126 } 127 128 function Save() { 129 if (empty ($this->TmpName)) {return $this -> GetError (2);} 130 else if ($this->FileSize > $this->MaxFileSize) {return $this -> GetError (1);} 131 else if ($this -> GetFileExtention ($this->FileName) == false) {return $this -> GetError (0);} 132 else if ($this -> ExistFile ()) {return $this -> GetError (3);} 133 134 else { 135 136 copy($this->TmpName,$this->PicDir.$this->FileName); 137 138 //echo $this -> GetInfo(); 139 140 } 141 } 142 } 143 144 ?>[code=php]/code