无法在PHP版本5.2.10中运行FPDF

无法在PHP版本5.2.10中运行FPDF,php,fpdf,Php,Fpdf,服务器信息显示PHP版本为5.2.10。我们的fPDF适用于5.3版,但不适用于5.2.8版 错误总是存在的 FPDF错误:缺少或不正确的图像文件: 有什么问题 代码段: <?php require('fpdf.php'); class PDF extends FPDF { var $aCols=array(); function Header() { //Logo $this->Image('UST-LOGO.jpg',25,10,18); //$this

服务器信息显示PHP版本为
5.2.10
。我们的
fPDF
适用于
5.3版
,但不适用于
5.2.8版

错误总是存在的

FPDF错误:缺少或不正确的图像文件:

有什么问题

代码段:

<?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();

?>

跳出的第一件事是:

$pdf->Image($file=$img, $x=null, $y=null, $w=150, $h=100, $type='jpeg', $link='');
快结束了。使用:

$pdf->Image($img, null, null, 150, 100, "jpeg", "");
看看这是否能解决问题。

可能是这一行:

$this->Image('UST-LOGO.jpg',25,10,18);
请将该行注释掉,然后重试。如果它现在起作用,你可能走错了路。我养成了使用神奇的“常量”
\uuuuu FILE\uuuu
来“绝对”指定所有文件的习惯

如果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)
。如果返回false,那么仔细查看一下您的目录(在服务器上!)。如果返回true,那么可能尝试用另一个图像替换图像,看看是否有效。

您可以发布一些代码来缩小范围吗?这两行在功能上是等效的,只是第一行还将值分配给一些(未使用的)变量。当然,duh。。。现在已经太晚了,很明显:-)我做了,但还是一样。FPDF错误:缺少或不正确的图像文件:C:\xampp\htdocs\exact\piechart.jpg