upload multiple image to pdf using fpdf php getting fatal error

29 Views Asked by At

I'm currently im trying to set up the pdf report using fpdf that includes multiple images on it.

After googling the best solution for my problem I still can't get it right.

My code is as follows:

include 'config.php';

if(isset($_POST['add_gambarvk']))
{
  $gambarvk_name = $_POST['gambarvk_name'];
  $gambarvk_image = $_FILES['gambarvk_image']['name'];
  $gambarvk_image_tmp_name = $_FILES['gambarvk_image']['tmp_name'];
  $size = getimagesize($gambarvk_image_tmp_name);
  $gambarvk_image_folder = './uploaded_img/' . $gambarvk_image;

  if(empty($gambarvk_name) || empty($gambarvk_image))
  {
    $message[] = 'please fill out all';
  }
  else 
  {
    // Get all the submitted data from the form
    $insert = "INSERT INTO gambarvk(name, image) VALUES('$gambarvk_name', '$gambarvk_image')";
    $upload = mysqli_query($conn,$insert);
  
    if($upload) 
    {
      //move the uploaded image into the folder: image
      move_uploaded_file($gambarvk_image_tmp_name, $gambarvk_image_folder);
      $message[] = 'Gambar berjaya dimasukkan';
    }
    else
    {
        $message[] = 'Gambar tidak berjaya dimasukkan';
    }
  }
};

$select = mysqli_query($conn, "SELECT * FROM gambarvk");

while($row = mysqli_fetch_assoc($select))
{

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

  //function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')

  $pdf->Image('./uploaded_img/'.$gambarvk_image,150,25,50,20, $image_format);
}

These errors and notices come out:

Notice: Undefined index: gambarvk_image in C:\xampp\htdocs\login\laporan_vk\laporanVK.php on line 821

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\login\laporan_vk\laporanVK.php on line 821

Notice: Undefined variable: gambarvk_image in C:\xampp\htdocs\login\laporan_vk\laporanVK.php on line 825

Fatal error: Uncaught Exception: FPDF error: Image file has no extension and no type was specified: ./uploaded_img/ in C:\xampp\htdocs\login\laporan_vk\laporanVK-fpdf\fpdf.php:267 Stack trace: #0 C:\xampp\htdocs\login\laporan_vk\laporanVK-fpdf\fpdf.php(881): FPDF->Error('Image file has ...') #1 C:\xampp\htdocs\login\laporan_vk\laporanVK.php(825): FPDF->Image('./uploaded_img/', 150, 25, 50, 20, '') #2 {main} thrown in C:\xampp\htdocs\login\laporan_vk\laporanVK-fpdf\fpdf.php on line 267.

If I use file extension like PNG or JPG:

//function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')

$pdf->Image('./uploaded_img.png/'.$gambarvk_image,150,25,50,20, $image_format);

The fatal error is changed to:

Fatal error: Uncaught Exception: FPDF error: Unsupported image type: png/ in C:\xampp\htdocs\login\laporan_vk\laporanVK-fpdf\fpdf.php:267 Stack trace: #0 C:\xampp\htdocs\login\laporan_vk\laporanVK-fpdf\fpdf.php(889): FPDF->Error('Unsupported ima...') #1 C:\xampp\htdocs\login\laporan_vk\laporanVK.php(825): FPDF->Image('./uploaded_img....', 150, 25, 50, 20, 'png/') #2 {main} thrown in C:\xampp\htdocs\login\laporan_vk\laporanVK-fpdf\fpdf.php on line 267

How can I solve these issues?

0

There are 0 best solutions below