hai. i would like to know is there have any video that can teach how to import image from database image folder to pdf using fpdf php. i already read some post here regarding to that issue by im not very clear and blur. actually i am very new in coding.

hope that anyone can help.

Recommended Answers

All 4 Replies

hai, dani thank for your reply. currently im trying to set up the pdf report using fpdf that include multiple images on it.

after googling the best solution for my problem im still cant get it and getting worse.

MY CODE IS LIKE BELOW;

  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);

 }

ERROR & NOTICE 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 put 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);

FATAL ERROR 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

so, how can i solve these issue.PLS HELP

You errors are showing undefined variables on line 821 and 825 of VK.php, and then a fatal error on line 267 of fpdf.php. What code are on and around those lines?

it's complaining the index "gambarvk_image" is not defined on line 821 which is code we can't see. I assume that the HTML form file input field is not named exactly "gambarvk_image" or maybe is named "gambarvk_image[]" or some variant or the form is not the right encoding. So check that first.

All the rest of the notices and errors are cascading because of that.

Also its not the best idea to get the type of image from the filename. If you have GD extension in your php enabled, a better method is something like the function image_type_to_mime_type

But verify the HTML form first

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.