當我嘗試運行將生成PDF文件的php代碼時,我收到了標題中提到的錯誤。這是當前代碼我使用:FPDF錯誤:圖像文件沒有擴展名,也沒有指定類型
$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理解文件類型嗎?
感謝您的回覆,並遺憾地忽略了$ image的相關代碼。問題是我的圖像文件沒有擴展名。但是,我刪除了他們的擴展名,以便我的網頁能夠打印出圖像,而不管它們以前在哪個擴展名中。是否有FPDF讀取和打印沒有擴展名的圖像? – Arastal
究竟是什麼意思?像'Image()'函數中的一個可選參數,讓您指導FPDF瞭解圖像類型? –
呃..我真的不知道什麼是可選參數。 http://i.imgur.com/oICdKXc.png鏈接顯示我的圖像當前存儲在的文件類型。基本上我需要允許我的PDF打印出圖像。有可能這樣做嗎? – Arastal