FPDF error: Unsupported image type: image/jpeg

FPDF error: Unsupported image type: image/jpeg

if(isset($_POST['sumit']))
  { 

   $con = mysqli_connect("localhost","root","","school");
       if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  } 

 $sname=$_POST['sname'];
  $category=$_POST['category'];
 $sadd=$_POST['sadd'];
 $file_name=$_FILES['file']['name'];
  $temp_name=$_FILES['file']['tmp_name'];
  $file_size = $_FILES['file']['size'];
 $file_type = $_FILES['file']['type'];

   $target_path  =  "Newfolder1";
$sql="SELECT * FROM imagetable WHERE   sname='$sname' and sadd='$sadd'and category='$category' and file='$target_path'";
 $result1 = mysqli_query($con, $sql);
  if(!mysqli_query($con, $sql)){
                die( "Could not execute sql: $sql"); 
                 }
$row = mysqli_fetch_row($result1);
$file=$row[0];


  $pdf=new fpdf();
$pdf->ADDPage();
$pdf->setfont('Arial','B', 16);

$pdf->Image($file,150,25,50,20,$file_type);


$pdf->Cell(0,10,'id',0,1);
$pdf->Cell(0,10,'sadd',0,1);
$pdf->Cell(0,10,'category',0,1);
$pdf->Cell(0,10,'sname',0,1);

$pdf->Output();}

这是给我图像类型,但所有这些都是通过数据库完成的 我的图像类型是在数据库中定义的,但我不知道。我收到了错误。 如果有人能找出错误,请回复

$pdf->Image("image/$user-signature.png" ,100, 213,-300);

这种格式适合我。尝试删除 $file 并在 $filetype

周围加上引号

问题是,您在 $file_type 变量(如 image/pngimage/jpeg)中指定 MIME 类型,并在 Image() 方法中使用它。您应该只指定图像格式。可能的值为(不区分大小写):JPG、JPEG、PNG 和 GIF。

所以先获取图片格式,像这样:

$image_format = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));

然后像这样调用 Image() 方法:

$pdf->Image($file,150,25,50,20,$image_format);

已编辑:

像这样更改您的 INSERT 查询,

$image_path = $target_path . DIRECTORY_SEPARATOR . $file_name;
if(move_uploaded_file($temp_name, $image_path)) { 
    $qry="INSERT INTO imagetable (file, sname, category, sadd, type,size, content ) values ('".$image_path."','".$sname."','".$category."','".$sadd."', '".$file_type."','".$file_size."', '".$Content."')"; 
    mysqli_query($con,$qry) or die("error in $qry == ----> ".mysqli_error()); 
}

并像这样更改您的 SELECT 语句,

// your code    

$target_path = "Newfolder1" . DIRECTORY_SEPARATOR . $file_name;
$sql="SELECT * FROM imagetable WHERE   sname='$sname' and sadd='$sadd'and category='$category' and file='$target_path'";

// your code