FPDF error: Unsupported image type: image/jpeg
10,011
The problem is, you're specifying the mime type in $file_type
variable(like image/png
or image/jpeg
) and using that in the Image()
method. You should only specify the image format. Possible values are (case insensitive): JPG, JPEG, PNG and GIF.
So first get the image format, like this:
$image_format = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
And then call the Image()
method like this:
$pdf->Image($file,150,25,50,20,$image_format);
Edited:
Change your INSERT
query like this,
$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());
}
And change your SELECT
statement like this,
// 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
Author by
Ishank Sainger
Updated on July 18, 2022Comments
-
Ishank Sainger almost 2 years
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();}
This is giving me the image type but all this is being done through database my image type is being defined in the db but I don't know. I'm gettting the error. If anyone could find out the error please reply