Dev Newb
Dev Newb

Reputation: 565

Get size of blob string before uploading to Mysql

I've read answered questions on this but none that addresses my exact issue. I'm creating a pdf after a form submission and uploading that pdf to MySQL. Is there a way with PHP to create the PDF and check its file size before I upload it? My script below works great. Turns pdf file to a string and places it in the database, I'm just not sure how to check the string size so I can add it as a variable. I'm new to PHP so not sure if this is even possible. Thanks.

$pdffilecontent = $pdf->Output('', 'S');
$name = "Feedback One";
$mime = "application/pdf";
//$md5  = md5_file($pdffilecontent);
$data = mysql_real_escape_string($pdffilecontent);
$link = "INSERT INTO `images` (`filename`, `mime_type`, `file_data`)VALUES ('{$name}', '{$mime}', '{$data}')";
$results = mysql_query($link) or die("Error in query: fda. " . mysql_error());
$id   = mysql_query("SELECT image_id FROM images ORDER BY image_id DESC LIMIT 0,1");
$temp = mysql_fetch_row($id);
$id   = $temp[0];
$answer = "INSERT INTO imagsub (imagesub_id, submission_id, user_id, image_id) VALUES ('NULL', '$hidden', '" . $outcome['id'] . "' ,'" . $id . "')";
    mysql_query($answer) or die("Error in query: fda2. " . mysql_error());

Upvotes: 4

Views: 1956

Answers (1)

paulsm4
paulsm4

Reputation: 121649

You probably solved this a year ago ... but, at Ren's request, I'm adding this as an answer (to clean up the unanswered queue):

Q: Have you tried "strlen ($pdffilecontent)"?

Upvotes: 3

Related Questions