Failed to Display PDF BLOB using FPDF










2















Im using FPDF/FPDI to merge the pdf from database with image as a header of the PDF. Searching for solution but no solution found yet so I post it here.



Here is my viewpdf.php code:



 <?php
/**
* Simply import all pages and different bounding boxes from different PDF documents.
*/
use setasignFpdi;
use setasignfpdf;
require_once 'config/config.php';
require_once 'vendor/autoload.php';
require_once 'vendor/setasign/fpdf/fpdf.php';

error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(2);
date_default_timezone_set('UTC');
$start = microtime(true);
$pdf = new FpdiFpdi();
//$pdf = new FpdiTcpdfFpdi('L', 'mm', 'A3');
if ($pdf instanceof TCPDF)
$pdf->SetProtection(['print'], '', 'owner');
$pdf->setPrintHeader(true);
$pdf->Image('logo-small.png',50,5,100);
$pdf->setPrintFooter(false);

$certid= $_GET['id'];
$sql="SELECT pdfblob from subject WHERE certid = '".$certid."' ";
$resultc = $virtual_con->query($sql);
while($row=mysqli_fetch_assoc($resultc))
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type:application/pdf");
header("Content-Transfer-Encoding: binary");
$a = (base64_decode($row["pdfblob"]));
$files = [$a];
foreach ($files as $file)
$pageCount = $pdf->setSourceFile($file);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++)
$pdf->AddPage();
$pageId = $pdf->importPage($pageNo, '/MediaBox');
$pageId = $pdf->importPage($pageNo, FpdiPdfReaderPageBoundaries::ART_BOX);
$s = $pdf->useTemplate($pageId, 10, 10, 200);


$file = uniqid().'.pdf';
$pdf->Output('I', 'simple.pdf');

//$pdf->Output('output/'.$file, 'I');
?>


It doesn't load the pdf from the database. "Failed to load PDF document."



Here is my upload.php to store the PDF in database. Is it my PDF is corrupt or something? I'm always using PDO for database interaction but this work implement mysqli so I need to follow the flow of the system.



<?php
include('config/config.php');
session_start();
$certid=$_POST['certid'];
$vendorid=$_POST['vendorid'];
$sid=$_POST['subjectid'];
$target_file = $_FILES["fileToUpload"]["name"];
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$uploadOk = 1;
if (isset($_POST['submit']))
$data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']);
$data = file_get_contents($data);
$data = base64_encode($data);
$uploadOk = 1;
if (isset($data))
$sql="UPDATE `subject` SET `pdfblob`='".$data."' WHERE (`Subjectid`='".$sid."')";
$result=mysqli_query($virtual_con,$sql);
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
$to="subjects.php?subjectid=".$sid."&certid=".$certid."&vendori=".$vendorid;
gotoInterface($to);

else
echo 'Fail to upload file';


if ($imageFileType !="pdf" )
echo "Sorry, PDF is allowed.";
$uploadOk = 0;

if (file_exists($target_file))
echo "Sorry, file already exists.";
$uploadOk = 0;

?>


I hope somebody could help me working on this code. I tried to solve em but still failed to succeed loading the output. I try to view the PDF without using FPDF but yet still not working. I'm wondering is my code make the BLOB corrupt while uploading?










share|improve this question
























  • What did mysqli_error($virtual_con) throw back on the queries? Is the column for the file indeed as a blob?

    – Funk Forty Niner
    Nov 16 '18 at 4:34












  • The column for the ['pdfblob'] is blob.

    – Aiman Hakeem
    Nov 16 '18 at 6:58











  • You answered the latter part of my question; what about the first part?

    – Funk Forty Niner
    Nov 16 '18 at 13:13











  • dah solve ke belum ni?

    – Fiido93
    Nov 16 '18 at 23:17











  • @Fiido93 belum solve lagi...

    – Aiman Hakeem
    Nov 17 '18 at 6:15















2















Im using FPDF/FPDI to merge the pdf from database with image as a header of the PDF. Searching for solution but no solution found yet so I post it here.



Here is my viewpdf.php code:



 <?php
/**
* Simply import all pages and different bounding boxes from different PDF documents.
*/
use setasignFpdi;
use setasignfpdf;
require_once 'config/config.php';
require_once 'vendor/autoload.php';
require_once 'vendor/setasign/fpdf/fpdf.php';

error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(2);
date_default_timezone_set('UTC');
$start = microtime(true);
$pdf = new FpdiFpdi();
//$pdf = new FpdiTcpdfFpdi('L', 'mm', 'A3');
if ($pdf instanceof TCPDF)
$pdf->SetProtection(['print'], '', 'owner');
$pdf->setPrintHeader(true);
$pdf->Image('logo-small.png',50,5,100);
$pdf->setPrintFooter(false);

$certid= $_GET['id'];
$sql="SELECT pdfblob from subject WHERE certid = '".$certid."' ";
$resultc = $virtual_con->query($sql);
while($row=mysqli_fetch_assoc($resultc))
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type:application/pdf");
header("Content-Transfer-Encoding: binary");
$a = (base64_decode($row["pdfblob"]));
$files = [$a];
foreach ($files as $file)
$pageCount = $pdf->setSourceFile($file);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++)
$pdf->AddPage();
$pageId = $pdf->importPage($pageNo, '/MediaBox');
$pageId = $pdf->importPage($pageNo, FpdiPdfReaderPageBoundaries::ART_BOX);
$s = $pdf->useTemplate($pageId, 10, 10, 200);


$file = uniqid().'.pdf';
$pdf->Output('I', 'simple.pdf');

//$pdf->Output('output/'.$file, 'I');
?>


It doesn't load the pdf from the database. "Failed to load PDF document."



Here is my upload.php to store the PDF in database. Is it my PDF is corrupt or something? I'm always using PDO for database interaction but this work implement mysqli so I need to follow the flow of the system.



<?php
include('config/config.php');
session_start();
$certid=$_POST['certid'];
$vendorid=$_POST['vendorid'];
$sid=$_POST['subjectid'];
$target_file = $_FILES["fileToUpload"]["name"];
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$uploadOk = 1;
if (isset($_POST['submit']))
$data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']);
$data = file_get_contents($data);
$data = base64_encode($data);
$uploadOk = 1;
if (isset($data))
$sql="UPDATE `subject` SET `pdfblob`='".$data."' WHERE (`Subjectid`='".$sid."')";
$result=mysqli_query($virtual_con,$sql);
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
$to="subjects.php?subjectid=".$sid."&certid=".$certid."&vendori=".$vendorid;
gotoInterface($to);

else
echo 'Fail to upload file';


if ($imageFileType !="pdf" )
echo "Sorry, PDF is allowed.";
$uploadOk = 0;

if (file_exists($target_file))
echo "Sorry, file already exists.";
$uploadOk = 0;

?>


I hope somebody could help me working on this code. I tried to solve em but still failed to succeed loading the output. I try to view the PDF without using FPDF but yet still not working. I'm wondering is my code make the BLOB corrupt while uploading?










share|improve this question
























  • What did mysqli_error($virtual_con) throw back on the queries? Is the column for the file indeed as a blob?

    – Funk Forty Niner
    Nov 16 '18 at 4:34












  • The column for the ['pdfblob'] is blob.

    – Aiman Hakeem
    Nov 16 '18 at 6:58











  • You answered the latter part of my question; what about the first part?

    – Funk Forty Niner
    Nov 16 '18 at 13:13











  • dah solve ke belum ni?

    – Fiido93
    Nov 16 '18 at 23:17











  • @Fiido93 belum solve lagi...

    – Aiman Hakeem
    Nov 17 '18 at 6:15













2












2








2


1






Im using FPDF/FPDI to merge the pdf from database with image as a header of the PDF. Searching for solution but no solution found yet so I post it here.



Here is my viewpdf.php code:



 <?php
/**
* Simply import all pages and different bounding boxes from different PDF documents.
*/
use setasignFpdi;
use setasignfpdf;
require_once 'config/config.php';
require_once 'vendor/autoload.php';
require_once 'vendor/setasign/fpdf/fpdf.php';

error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(2);
date_default_timezone_set('UTC');
$start = microtime(true);
$pdf = new FpdiFpdi();
//$pdf = new FpdiTcpdfFpdi('L', 'mm', 'A3');
if ($pdf instanceof TCPDF)
$pdf->SetProtection(['print'], '', 'owner');
$pdf->setPrintHeader(true);
$pdf->Image('logo-small.png',50,5,100);
$pdf->setPrintFooter(false);

$certid= $_GET['id'];
$sql="SELECT pdfblob from subject WHERE certid = '".$certid."' ";
$resultc = $virtual_con->query($sql);
while($row=mysqli_fetch_assoc($resultc))
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type:application/pdf");
header("Content-Transfer-Encoding: binary");
$a = (base64_decode($row["pdfblob"]));
$files = [$a];
foreach ($files as $file)
$pageCount = $pdf->setSourceFile($file);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++)
$pdf->AddPage();
$pageId = $pdf->importPage($pageNo, '/MediaBox');
$pageId = $pdf->importPage($pageNo, FpdiPdfReaderPageBoundaries::ART_BOX);
$s = $pdf->useTemplate($pageId, 10, 10, 200);


$file = uniqid().'.pdf';
$pdf->Output('I', 'simple.pdf');

//$pdf->Output('output/'.$file, 'I');
?>


It doesn't load the pdf from the database. "Failed to load PDF document."



Here is my upload.php to store the PDF in database. Is it my PDF is corrupt or something? I'm always using PDO for database interaction but this work implement mysqli so I need to follow the flow of the system.



<?php
include('config/config.php');
session_start();
$certid=$_POST['certid'];
$vendorid=$_POST['vendorid'];
$sid=$_POST['subjectid'];
$target_file = $_FILES["fileToUpload"]["name"];
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$uploadOk = 1;
if (isset($_POST['submit']))
$data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']);
$data = file_get_contents($data);
$data = base64_encode($data);
$uploadOk = 1;
if (isset($data))
$sql="UPDATE `subject` SET `pdfblob`='".$data."' WHERE (`Subjectid`='".$sid."')";
$result=mysqli_query($virtual_con,$sql);
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
$to="subjects.php?subjectid=".$sid."&certid=".$certid."&vendori=".$vendorid;
gotoInterface($to);

else
echo 'Fail to upload file';


if ($imageFileType !="pdf" )
echo "Sorry, PDF is allowed.";
$uploadOk = 0;

if (file_exists($target_file))
echo "Sorry, file already exists.";
$uploadOk = 0;

?>


I hope somebody could help me working on this code. I tried to solve em but still failed to succeed loading the output. I try to view the PDF without using FPDF but yet still not working. I'm wondering is my code make the BLOB corrupt while uploading?










share|improve this question
















Im using FPDF/FPDI to merge the pdf from database with image as a header of the PDF. Searching for solution but no solution found yet so I post it here.



Here is my viewpdf.php code:



 <?php
/**
* Simply import all pages and different bounding boxes from different PDF documents.
*/
use setasignFpdi;
use setasignfpdf;
require_once 'config/config.php';
require_once 'vendor/autoload.php';
require_once 'vendor/setasign/fpdf/fpdf.php';

error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(2);
date_default_timezone_set('UTC');
$start = microtime(true);
$pdf = new FpdiFpdi();
//$pdf = new FpdiTcpdfFpdi('L', 'mm', 'A3');
if ($pdf instanceof TCPDF)
$pdf->SetProtection(['print'], '', 'owner');
$pdf->setPrintHeader(true);
$pdf->Image('logo-small.png',50,5,100);
$pdf->setPrintFooter(false);

$certid= $_GET['id'];
$sql="SELECT pdfblob from subject WHERE certid = '".$certid."' ";
$resultc = $virtual_con->query($sql);
while($row=mysqli_fetch_assoc($resultc))
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type:application/pdf");
header("Content-Transfer-Encoding: binary");
$a = (base64_decode($row["pdfblob"]));
$files = [$a];
foreach ($files as $file)
$pageCount = $pdf->setSourceFile($file);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++)
$pdf->AddPage();
$pageId = $pdf->importPage($pageNo, '/MediaBox');
$pageId = $pdf->importPage($pageNo, FpdiPdfReaderPageBoundaries::ART_BOX);
$s = $pdf->useTemplate($pageId, 10, 10, 200);


$file = uniqid().'.pdf';
$pdf->Output('I', 'simple.pdf');

//$pdf->Output('output/'.$file, 'I');
?>


It doesn't load the pdf from the database. "Failed to load PDF document."



Here is my upload.php to store the PDF in database. Is it my PDF is corrupt or something? I'm always using PDO for database interaction but this work implement mysqli so I need to follow the flow of the system.



<?php
include('config/config.php');
session_start();
$certid=$_POST['certid'];
$vendorid=$_POST['vendorid'];
$sid=$_POST['subjectid'];
$target_file = $_FILES["fileToUpload"]["name"];
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$uploadOk = 1;
if (isset($_POST['submit']))
$data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']);
$data = file_get_contents($data);
$data = base64_encode($data);
$uploadOk = 1;
if (isset($data))
$sql="UPDATE `subject` SET `pdfblob`='".$data."' WHERE (`Subjectid`='".$sid."')";
$result=mysqli_query($virtual_con,$sql);
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
$to="subjects.php?subjectid=".$sid."&certid=".$certid."&vendori=".$vendorid;
gotoInterface($to);

else
echo 'Fail to upload file';


if ($imageFileType !="pdf" )
echo "Sorry, PDF is allowed.";
$uploadOk = 0;

if (file_exists($target_file))
echo "Sorry, file already exists.";
$uploadOk = 0;

?>


I hope somebody could help me working on this code. I tried to solve em but still failed to succeed loading the output. I try to view the PDF without using FPDF but yet still not working. I'm wondering is my code make the BLOB corrupt while uploading?







php mysqli file-upload blob fpdf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 4:37









Funk Forty Niner

1




1










asked Nov 16 '18 at 3:56









Aiman HakeemAiman Hakeem

111




111












  • What did mysqli_error($virtual_con) throw back on the queries? Is the column for the file indeed as a blob?

    – Funk Forty Niner
    Nov 16 '18 at 4:34












  • The column for the ['pdfblob'] is blob.

    – Aiman Hakeem
    Nov 16 '18 at 6:58











  • You answered the latter part of my question; what about the first part?

    – Funk Forty Niner
    Nov 16 '18 at 13:13











  • dah solve ke belum ni?

    – Fiido93
    Nov 16 '18 at 23:17











  • @Fiido93 belum solve lagi...

    – Aiman Hakeem
    Nov 17 '18 at 6:15

















  • What did mysqli_error($virtual_con) throw back on the queries? Is the column for the file indeed as a blob?

    – Funk Forty Niner
    Nov 16 '18 at 4:34












  • The column for the ['pdfblob'] is blob.

    – Aiman Hakeem
    Nov 16 '18 at 6:58











  • You answered the latter part of my question; what about the first part?

    – Funk Forty Niner
    Nov 16 '18 at 13:13











  • dah solve ke belum ni?

    – Fiido93
    Nov 16 '18 at 23:17











  • @Fiido93 belum solve lagi...

    – Aiman Hakeem
    Nov 17 '18 at 6:15
















What did mysqli_error($virtual_con) throw back on the queries? Is the column for the file indeed as a blob?

– Funk Forty Niner
Nov 16 '18 at 4:34






What did mysqli_error($virtual_con) throw back on the queries? Is the column for the file indeed as a blob?

– Funk Forty Niner
Nov 16 '18 at 4:34














The column for the ['pdfblob'] is blob.

– Aiman Hakeem
Nov 16 '18 at 6:58





The column for the ['pdfblob'] is blob.

– Aiman Hakeem
Nov 16 '18 at 6:58













You answered the latter part of my question; what about the first part?

– Funk Forty Niner
Nov 16 '18 at 13:13





You answered the latter part of my question; what about the first part?

– Funk Forty Niner
Nov 16 '18 at 13:13













dah solve ke belum ni?

– Fiido93
Nov 16 '18 at 23:17





dah solve ke belum ni?

– Fiido93
Nov 16 '18 at 23:17













@Fiido93 belum solve lagi...

– Aiman Hakeem
Nov 17 '18 at 6:15





@Fiido93 belum solve lagi...

– Aiman Hakeem
Nov 17 '18 at 6:15












2 Answers
2






active

oldest

votes


















0














I'm making this as an answer instead of a comment because it will be too long for a comment. Follow these steps to determine where it's going wrong.



  1. Your problem MIGHT be that your line $data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']); might be coorrupting the file. Try saving a known good pdf to the database from local storage and not using the upload file process and then try to decode it again. If you can turn that back in to a pdf, then the your upload is corrupting it. Otherwise, skip to step 2.

  2. Encode a file and save the output before uploading to the database (in a text editor). Then, query the database for that file and before you decode it, paste that string in to a text editor also and compare the two strings. If they are different, you know your database is doing something to the file. If they're the same, I don't know what else to tell you.

I hope this helped.






share|improve this answer


















  • 1





    Actually, escaping the file input is required when saving as a blob. Otherwise, it will throw an error.

    – Funk Forty Niner
    Nov 16 '18 at 4:32












  • I've always done my best to avoid saving data that way so I didn't know that (or I did and forgot). However, it's still possible that his data is getting corrupted somehow in the process. Best to check and make sure.

    – Difster
    Nov 16 '18 at 4:35











  • I could replace mysqli_real_escape_string() by replacing addslashes. It could still upload. But for security purpose I replace addslashes with mysqli_real_escape_string()

    – Aiman Hakeem
    Nov 16 '18 at 7:01


















0














If your column in mysql pdfblob type are blob .



Then i suggest you to change the type to LONGBLOB type.



Since BLOB type in MySQL are only stores up to 64KB.



If still doesn't work then Change in the my.ini



max_allowed_packet=500M





share|improve this answer

























  • my datatype already changed to long blob yet still not working.

    – Aiman Hakeem
    Nov 21 '18 at 10:29











  • i have updated my answer @AimanHakeem

    – Fiido93
    Nov 21 '18 at 10:52










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331214%2ffailed-to-display-pdf-blob-using-fpdf%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I'm making this as an answer instead of a comment because it will be too long for a comment. Follow these steps to determine where it's going wrong.



  1. Your problem MIGHT be that your line $data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']); might be coorrupting the file. Try saving a known good pdf to the database from local storage and not using the upload file process and then try to decode it again. If you can turn that back in to a pdf, then the your upload is corrupting it. Otherwise, skip to step 2.

  2. Encode a file and save the output before uploading to the database (in a text editor). Then, query the database for that file and before you decode it, paste that string in to a text editor also and compare the two strings. If they are different, you know your database is doing something to the file. If they're the same, I don't know what else to tell you.

I hope this helped.






share|improve this answer


















  • 1





    Actually, escaping the file input is required when saving as a blob. Otherwise, it will throw an error.

    – Funk Forty Niner
    Nov 16 '18 at 4:32












  • I've always done my best to avoid saving data that way so I didn't know that (or I did and forgot). However, it's still possible that his data is getting corrupted somehow in the process. Best to check and make sure.

    – Difster
    Nov 16 '18 at 4:35











  • I could replace mysqli_real_escape_string() by replacing addslashes. It could still upload. But for security purpose I replace addslashes with mysqli_real_escape_string()

    – Aiman Hakeem
    Nov 16 '18 at 7:01















0














I'm making this as an answer instead of a comment because it will be too long for a comment. Follow these steps to determine where it's going wrong.



  1. Your problem MIGHT be that your line $data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']); might be coorrupting the file. Try saving a known good pdf to the database from local storage and not using the upload file process and then try to decode it again. If you can turn that back in to a pdf, then the your upload is corrupting it. Otherwise, skip to step 2.

  2. Encode a file and save the output before uploading to the database (in a text editor). Then, query the database for that file and before you decode it, paste that string in to a text editor also and compare the two strings. If they are different, you know your database is doing something to the file. If they're the same, I don't know what else to tell you.

I hope this helped.






share|improve this answer


















  • 1





    Actually, escaping the file input is required when saving as a blob. Otherwise, it will throw an error.

    – Funk Forty Niner
    Nov 16 '18 at 4:32












  • I've always done my best to avoid saving data that way so I didn't know that (or I did and forgot). However, it's still possible that his data is getting corrupted somehow in the process. Best to check and make sure.

    – Difster
    Nov 16 '18 at 4:35











  • I could replace mysqli_real_escape_string() by replacing addslashes. It could still upload. But for security purpose I replace addslashes with mysqli_real_escape_string()

    – Aiman Hakeem
    Nov 16 '18 at 7:01













0












0








0







I'm making this as an answer instead of a comment because it will be too long for a comment. Follow these steps to determine where it's going wrong.



  1. Your problem MIGHT be that your line $data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']); might be coorrupting the file. Try saving a known good pdf to the database from local storage and not using the upload file process and then try to decode it again. If you can turn that back in to a pdf, then the your upload is corrupting it. Otherwise, skip to step 2.

  2. Encode a file and save the output before uploading to the database (in a text editor). Then, query the database for that file and before you decode it, paste that string in to a text editor also and compare the two strings. If they are different, you know your database is doing something to the file. If they're the same, I don't know what else to tell you.

I hope this helped.






share|improve this answer













I'm making this as an answer instead of a comment because it will be too long for a comment. Follow these steps to determine where it's going wrong.



  1. Your problem MIGHT be that your line $data = mysqli_real_escape_string($virtual_con,$_FILES['fileToUpload']['tmp_name']); might be coorrupting the file. Try saving a known good pdf to the database from local storage and not using the upload file process and then try to decode it again. If you can turn that back in to a pdf, then the your upload is corrupting it. Otherwise, skip to step 2.

  2. Encode a file and save the output before uploading to the database (in a text editor). Then, query the database for that file and before you decode it, paste that string in to a text editor also and compare the two strings. If they are different, you know your database is doing something to the file. If they're the same, I don't know what else to tell you.

I hope this helped.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 4:29









DifsterDifster

3,02811730




3,02811730







  • 1





    Actually, escaping the file input is required when saving as a blob. Otherwise, it will throw an error.

    – Funk Forty Niner
    Nov 16 '18 at 4:32












  • I've always done my best to avoid saving data that way so I didn't know that (or I did and forgot). However, it's still possible that his data is getting corrupted somehow in the process. Best to check and make sure.

    – Difster
    Nov 16 '18 at 4:35











  • I could replace mysqli_real_escape_string() by replacing addslashes. It could still upload. But for security purpose I replace addslashes with mysqli_real_escape_string()

    – Aiman Hakeem
    Nov 16 '18 at 7:01












  • 1





    Actually, escaping the file input is required when saving as a blob. Otherwise, it will throw an error.

    – Funk Forty Niner
    Nov 16 '18 at 4:32












  • I've always done my best to avoid saving data that way so I didn't know that (or I did and forgot). However, it's still possible that his data is getting corrupted somehow in the process. Best to check and make sure.

    – Difster
    Nov 16 '18 at 4:35











  • I could replace mysqli_real_escape_string() by replacing addslashes. It could still upload. But for security purpose I replace addslashes with mysqli_real_escape_string()

    – Aiman Hakeem
    Nov 16 '18 at 7:01







1




1





Actually, escaping the file input is required when saving as a blob. Otherwise, it will throw an error.

– Funk Forty Niner
Nov 16 '18 at 4:32






Actually, escaping the file input is required when saving as a blob. Otherwise, it will throw an error.

– Funk Forty Niner
Nov 16 '18 at 4:32














I've always done my best to avoid saving data that way so I didn't know that (or I did and forgot). However, it's still possible that his data is getting corrupted somehow in the process. Best to check and make sure.

– Difster
Nov 16 '18 at 4:35





I've always done my best to avoid saving data that way so I didn't know that (or I did and forgot). However, it's still possible that his data is getting corrupted somehow in the process. Best to check and make sure.

– Difster
Nov 16 '18 at 4:35













I could replace mysqli_real_escape_string() by replacing addslashes. It could still upload. But for security purpose I replace addslashes with mysqli_real_escape_string()

– Aiman Hakeem
Nov 16 '18 at 7:01





I could replace mysqli_real_escape_string() by replacing addslashes. It could still upload. But for security purpose I replace addslashes with mysqli_real_escape_string()

– Aiman Hakeem
Nov 16 '18 at 7:01













0














If your column in mysql pdfblob type are blob .



Then i suggest you to change the type to LONGBLOB type.



Since BLOB type in MySQL are only stores up to 64KB.



If still doesn't work then Change in the my.ini



max_allowed_packet=500M





share|improve this answer

























  • my datatype already changed to long blob yet still not working.

    – Aiman Hakeem
    Nov 21 '18 at 10:29











  • i have updated my answer @AimanHakeem

    – Fiido93
    Nov 21 '18 at 10:52















0














If your column in mysql pdfblob type are blob .



Then i suggest you to change the type to LONGBLOB type.



Since BLOB type in MySQL are only stores up to 64KB.



If still doesn't work then Change in the my.ini



max_allowed_packet=500M





share|improve this answer

























  • my datatype already changed to long blob yet still not working.

    – Aiman Hakeem
    Nov 21 '18 at 10:29











  • i have updated my answer @AimanHakeem

    – Fiido93
    Nov 21 '18 at 10:52













0












0








0







If your column in mysql pdfblob type are blob .



Then i suggest you to change the type to LONGBLOB type.



Since BLOB type in MySQL are only stores up to 64KB.



If still doesn't work then Change in the my.ini



max_allowed_packet=500M





share|improve this answer















If your column in mysql pdfblob type are blob .



Then i suggest you to change the type to LONGBLOB type.



Since BLOB type in MySQL are only stores up to 64KB.



If still doesn't work then Change in the my.ini



max_allowed_packet=500M






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 10:52

























answered Nov 16 '18 at 23:29









Fiido93Fiido93

1,48511019




1,48511019












  • my datatype already changed to long blob yet still not working.

    – Aiman Hakeem
    Nov 21 '18 at 10:29











  • i have updated my answer @AimanHakeem

    – Fiido93
    Nov 21 '18 at 10:52

















  • my datatype already changed to long blob yet still not working.

    – Aiman Hakeem
    Nov 21 '18 at 10:29











  • i have updated my answer @AimanHakeem

    – Fiido93
    Nov 21 '18 at 10:52
















my datatype already changed to long blob yet still not working.

– Aiman Hakeem
Nov 21 '18 at 10:29





my datatype already changed to long blob yet still not working.

– Aiman Hakeem
Nov 21 '18 at 10:29













i have updated my answer @AimanHakeem

– Fiido93
Nov 21 '18 at 10:52





i have updated my answer @AimanHakeem

– Fiido93
Nov 21 '18 at 10:52

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331214%2ffailed-to-display-pdf-blob-using-fpdf%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線