当我尝试运行将生成 PDF 文件的 php 代码时,我收到了标题中提到的错误。这是我正在使用的当前代码:
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
foreach($inventories as $key => $inventories) :
$image = $inventories['image'];
$resourceID = $inventories['resourceID'];
$learningcentre = $inventories['learningcentre'];
$title = $inventories['title'];
$quantity = $inventories['quantity'];
$description = $inventories['description'];
$html= 'Resource ID: '. $resourceID. '<br>Title: '.$title.'<br>Learning Centre: '.$learningcentre.'<br>Quantity: '.$quantity.'<br>Description: '.$description.'<br><br>';
$pdf->Image('images/'.$image,10,6,30);
$pdf->WriteHTML($html);
endforeach;
$pdf->Output();
我的图像当前存储在图像文件夹中,我已使用以下代码将图像文件类型转换为“文件”:
$fileTypes = array(
'image/pjpeg',
'image/jpeg',
'image/png',
'image/gif'
);
// default value for unsuccessful move file
$successfullyMoveFile = false;
// the name of the input type
$fileInputName = 'file';
// an array to store all the possible errors related to uploading a file
$fileErrorMessages = array();
//if file is not empty
$uploadFile = !empty($_FILES);
if ($uploadFile)
{
$fileUploaded = $_FILES[$fileInputName];
// if we have errors while uploading!!
if ($fileUploaded['error'] != UPLOAD_ERR_OK)
{
$errorCode = $fileUploaded['error']; // this could be 1, 2, 3, 4, 5, 6, or 7.
$fileErrorMessages['file'] = $uploadErrors[$errorCode];
}
// now we check for file type
$fileTypeUploaded = $fileUploaded['type'];
$fileTypeNotAllowed = !in_array($fileTypeUploaded, $fileTypes);
if ($fileTypeNotAllowed)
{
$fileErrorMessages['file'] = 'You should upload a .jpg, .png or .gif file';
}
// if successful, we want to copy the file to our images folder
if ($fileUploaded['error'] == UPLOAD_ERR_OK)
{
$successfullyMoveFile = move_uploaded_file($fileUploaded["tmp_name"], $imagesDirectory . $newFileName);
}
}
我认为问题出在文件类型上。有什么方法可以让 FPDF 理解文件类型吗?