2009-10-15 25 views
0

服務器信息表明PHP版本爲5.2.10。我們的fPDF適用於版本5.3,但不適用於版本5.2.8無法在PHP 5.2.10版本中運行FPDF

的誤差始終

FPDF error: Missing or incorrect image file:

問題是什麼?

代碼段:

<?php 
require('fpdf.php'); 

class PDF extends FPDF 
{ 
var $aCols=array(); 
function Header() 
{ 
    //Logo 
    $this->Image('UST-LOGO.jpg',25,10,18); 
    //$this->Ln(5); 
    //$this->Cell(0,10,$date); 
    $this->SetFont('Arial','B',12); 
    //Move to the right 
    //$this->Cell(80); 
    //Title 
    $this->Cell(0,10,'University of Santo Tomas',0,0,'C'); 
    $this->Ln(5); 
    $this->SetFont('Arial','I',12); 
    $this->Cell(0,10,'Office for Student Affairs',0,0,'C'); 
    $this->Ln(5); 
    $this->Cell(0,10,'Annual Report',0,0,'C'); 
    $this->Ln(15); 
} 
function TableHeader() 
{ 
    $this->SetFont('Arial','B',12); 
    $this->SetX($this->TableX); 
    $fill=!empty($this->HeaderColor); 
    if($fill) 
     $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1], 
           $this->HeaderColor[2]); 
    foreach($this->aCols as $col) 
     $this->Cell($col['w'],6,$col['c'],1,0,'C',$fill); 
    $this->Ln(); 
} 

function Row($data) 
{ 
    $this->SetX($this->TableX); 
    $ci=$this->ColorIndex; 
    $fill=!empty($this->RowColors[$ci]); 
    if($fill) 
     $this->SetFillColor($this->RowColors[$ci][0], 
     $this->RowColors[$ci][1],$this->RowColors[$ci][2]); 
    foreach($this->aCols as $col) 
     $this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill); 
    $this->Ln(); 
    $this->ColorIndex=1-$ci; 
} 
function CalcWidths($width,$align) 
{ 
    //Compute the widths of the columns 
    $TableWidth=0; 
    foreach($this->aCols as $i=>$col) 
    { 
     $w=$col['w']; 
     if($w==-1) 
      $w=$width/count($this->aCols); 
     elseif(substr($w,-1)=='%') 
      $w=$w/100*$width; 
     $this->aCols[$i]['w']=$w; 
     $TableWidth+=$w; 
    } 
    //Compute the abscissa of the table 
    if($align=='C') 
     $this->TableX=max(($this->w-$TableWidth)/2,0); 
    elseif($align=='R') 
     $this->TableX=max($this->w-$this->rMargin-$TableWidth,0); 
    else 
     $this->TableX=$this->lMargin; 
} 
function AddCol($field=-1,$width=-1,$caption='',$align='L') 
{ 
    //Add a column to the table 
    if($field==-1) 
     $field=count($this->aCols); 
    $this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align); 
} 
function Table($query,$prop=array()) 
{ 
    //Issue query 
    $res=mysql_query($query) or die 
    ('Error: '.mysql_error()."<BR>Query: $query"); 
    //Add all columns if none was specified 
    if(count($this->aCols)==0) 
    { 
     $nb=mysql_num_fields($res); 
     for($i=0;$i<$nb;$i++) 
      $this->AddCol(); 
    } 
    //Retrieve column names when not specified 
    foreach($this->aCols as $i=>$col) 
    { 
     if($col['c']=='') 
     { 
      if(is_string($col['f'])) 
       $this->aCols[$i]['c']=ucfirst($col['f']); 
      else 
       $this->aCols[$i]['c']=ucfirst 
         (mysql_field_name($res,$col['f'])); 
     } 
    } 
    //Handle properties 
    if(!isset($prop['width'])) 
     $prop['width']=0; 
    if($prop['width']==0) 
     $prop['width']=$this->w-$this->lMargin-$this->rMargin; 
    if(!isset($prop['align'])) 
     $prop['align']='C'; 
    if(!isset($prop['padding'])) 
     $prop['padding']=$this->cMargin; 
    $cMargin=$this->cMargin; 
    $this->cMargin=$prop['padding']; 
    if(!isset($prop['HeaderColor'])) 
     $prop['HeaderColor']=array(); 
    $this->HeaderColor=$prop['HeaderColor']; 
    if(!isset($prop['color1'])) 
     $prop['color1']=array(); 
    if(!isset($prop['color2'])) 
     $prop['color2']=array(); 
    $this->RowColors=array($prop['color1'],$prop['color2']); 
    //Compute column widths 
    $this->CalcWidths($prop['width'],$prop['align']); 
    //Print header 
    $this->TableHeader(); 
    //Print rows 
    $this->SetFont('Arial','',11); 
    $this->ColorIndex=0; 
    $this->ProcessingTable=true; 
    while($row=mysql_fetch_array($res)) 
     $this->Row($row); 
    $this->ProcessingTable=false; 
    $this->cMargin=$cMargin; 
    $this->aCols=array(); 
} 

function Footer() 
{ 
    //Position at 1.5 cm from bottom 
    $this->SetY(-15); 
    $this->SetFont('Arial','I',8); 
    $this->Cell(0,10,'Generated by ExAct: Expert System 
       for Activity Proposals',0,0,'L'); 
    $this->Ln(5); 
    $this->Cell(0,10,$date); 
} 
} 

include("phpgraphlib.php"); 
include("phpgraphlib_pie.php"); 
include("connection.php"); 
/*$id=$_GET['id']; 
     $result=mysql_query("select * from approved where id='$id'"); 
     $row=mysql_fetch_assoc($result); 
     $_SESSION['other_id']=$id; 
     $id=$_SESSION['other_id'];*/ 
$querypa = "SELECT COUNT(nature) FROM approved WHERE nature='Parade'"; 
$resultpa = mysql_query($querypa); 
$printpa = mysql_result($resultpa,0); 
$querycs = "SELECT COUNT(nature) FROM approved WHERE 
         nature='Community Service'"; 
$resultcs = mysql_query($querycs); 
$printcs = mysql_result($resultcs,0); 
$queryga = "SELECT COUNT(nature) FROM approved WHERE 
         nature='General Assembly'"; 
$resultga = mysql_query($queryga); 
$printga = mysql_result($resultga,0); 
$querypl = "SELECT COUNT(nature) FROM approved WHERE 
      nature='Play/Showcase/Socio-Cultural Show/Film Showing'"; 
$resultpl = mysql_query($querypl); 
$printpl = mysql_result($resultpl,0); 
$queryco = "SELECT COUNT(nature) FROM approved WHERE 
         nature='Competition/Sportsfest'"; 
$resultco = mysql_query($queryco); 
$printco = mysql_result($resultco,0); 
$queryfr = "SELECT COUNT(nature) FROM approved WHERE 
         nature='Fund Raising'"; 
$resultfr = mysql_query($queryfr); 
$printfr = mysql_result($resultfr,0); 
$queryse = "SELECT COUNT(nature) FROM approved WHERE 
         nature='Seminar/Convention/Conference/Training'"; 
$resultse = mysql_query($queryse); 
$printse = mysql_result($resultse,0); 


$totalAct=$printpa+$printga+$printpl+$printcs+$printco+$printfr+$printse; 
$avepa=($printpa/$totalAct)*100; 
$avecs=($printcs/$totalAct)*100; 
$avega=($printga/$totalAct)*100; 
$avepl=($printpl/$totalAct)*100; 
$aveco=($printco/$totalAct)*100; 
$avefr=($printfr/$totalAct)*100; 
$avese=($printse/$totalAct)*100; 
$pa=number_format($avepa,2); 
$cs=number_format($avecs,2); 
$ga=number_format($avega,2); 
$pl=number_format($avepl,2); 
$co=number_format($aveco,2); 
$fr=number_format($avefr,2); 
$se=number_format($avese,2); 

//$querydb="INSERT INTO report(nature,totalAct) 
        values('Parade','$pa'),('General //Assembly','$ga'), 
          ('Play','$pl'),('Community Service','$cs')"; 
//$resultdb = mysql_query($querydb); 

$date=date("m-d-Y"); 


$url = 'http://exact.byethost10.com/sample_pie.php'; 
$img = 'C:/xampp/htdocs/EXACT/piechart.jpg'; 
file_put_contents($img, file_get_contents($url)); 

$pdf=new PDF('L','mm','Letter'); 
$pdf->SetRightMargin(20); 
$pdf->SetLeftMargin(20); 
$pdf->AddPage(); 
$pdf->SetFont('Arial','',12); 

//Second table: specify 3 columns 
$pdf->Cell(0,10,$date); 
$pdf->Ln(10); 
$pdf->AddCol('org',52,'org','L'); 
$pdf->AddCol('title',83,'title','L'); 
$pdf->AddCol('nature',92,'','C'); 
$pdf->AddCol('start_date',25,'start_date','L'); 
$pdf->AddCol('end_date',25,'end_date','L'); 
$prop=array('HeaderColor'=>array(255,150,100), 
      //'color1'=>array(210,245,255), 
      'color2'=>array(255,255,210), 
      'padding'=>2); 
$pdf->Table('select org, title, nature, start_date, 
      end_date from approved order by id',$prop); 

$pdf->Cell(0,10,'Parade:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$printpa); 
$pdf->SetX(120);$pdf->Cell(0,10,$pa); 
$pdf->SetX(130);$pdf->Cell(0,10,'%'); 
$pdf->Ln(5); 
$pdf->Cell(0,10,'Community Service:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$printcs); 
$pdf->SetX(120);$pdf->Cell(0,10,$cs); 
$pdf->SetX(130);$pdf->Cell(0,10,'%'); 
$pdf->Ln(5); 
$pdf->Cell(0,10,'General Assembly:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$printga); 
$pdf->SetX(120);$pdf->Cell(0,10,$ga); 
$pdf->SetX(130);$pdf->Cell(0,10,'%'); 
$pdf->Ln(5); 
$pdf->Cell(0,10,'Play/Showcase/Socio-Cultural Show/Film Showing:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$printpl); 
$pdf->SetX(120);$pdf->Cell(0,10,$pl); 
$pdf->SetX(130);$pdf->Cell(0,10,'%'); 
$pdf->Ln(5); 
$pdf->Cell(0,10,'Competition/Sportsfest:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$printco); 
$pdf->SetX(120);$pdf->Cell(0,10,$co); 
$pdf->SetX(130);$pdf->Cell(0,10,'%'); 
$pdf->Ln(5); 
$pdf->Cell(0,10,'Fund Raising:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$printfr); 
$pdf->SetX(120);$pdf->Cell(0,10,$fr); 
$pdf->SetX(130);$pdf->Cell(0,10,'%'); 
$pdf->Ln(5); 
$pdf->Cell(0,10,'Seminar/Convention/Conference/Training:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$printse); 
$pdf->SetX(120);$pdf->Cell(0,10,$se); 
$pdf->SetX(130);$pdf->Cell(0,10,'%'); 
$pdf->Ln(15); 
$pdf->SetFont('Arial','B',12); 
$pdf->Cell(0,10,'Total number of Activities:'); 
$pdf->SetX(110);$pdf->Cell(0,10,$totalAct); 
$pdf->SetX(120);$pdf->Cell(0,10,' 100 %'); 
$pdf->Ln(15); 
$pdf->SetX(65); 
$pdf->Image($file=$img, $x=null, $y=null, 
      $w=150, $h=100, $type='jpeg', $link=''); 
$pdf->Output(); 

?> 
+0

你可以發佈一些代碼,可能會縮小它? – richsage 2009-10-15 22:16:00

+1

接受一些答案 – 2009-10-16 00:57:44

回答

0

即跳出的第一件事是:

$pdf->Image($file=$img, $x=null, $y=null, $w=150, $h=100, $type='jpeg', $link=''); 

接近尾聲。使用:

$pdf->Image($img, null, null, 150, 100, "jpeg", ""); 

看看這是否解決了它。

+0

這兩條線在功能上是等價的,它只是第一個也將值賦給一些(未使用的)變量 – nickf 2009-10-15 22:25:36

+0

當然啊......這裏太遲了,顯然:-) – richsage 2009-10-15 22:27:50

1

這可能是這一行:

$this->Image('UST-LOGO.jpg',25,10,18); 

評論該行並再次嘗試。如果它現在可以工作,你可能會弄錯路徑。我習慣使用魔術「常量」__FILE__「絕對地」指定我的所有文件。

如果UST-LOGO是因爲該文件您發佈的源相同的目錄,那麼你可以在你的代碼改成這樣:

$this->Image(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'UST-LOGO.jpg',25,10,18); 

編輯:這裏是代碼從這就引起該錯誤的FPDF類:

// line 1199 
$a=GetImageSize($file); 
if(!$a) 
    $this->Error('Missing or incorrect image file: '.$file); 

誤差只能由文件引起的或者不存在的(路徑是錯誤的)或無法讀取圖像數據(該文件已損壞或文件權限阻止它)

我建議在你的代碼(或FPDF代碼)檢查file_exists($file)添加一行。如果返回false,那麼仔細看看你的目錄(在服務器上!)。如果這返回true,那麼也許嘗試替換另一個圖像,看看是否有效。

+0

我做了這但它仍然是一樣的。 FPDF錯誤:缺少或不正確的圖像文件:C:\ xampp \ htdocs \ exact \ piechart.jpg – noob 2009-10-15 22:27:27

+0

* *有一個文件,對吧? – nickf 2009-10-15 22:31:21

+0

是的那個文件在那裏 – noob 2009-10-15 22:38:33