当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Insert pdf as blob and display

问题描述:

So I'm getting a Pdf file send to my webservice for me to upload,

it's send to me as a base64Binary type variable,

and uploaded using below script :

function SaveEIM($parameters)

{

mysql_query("INSERT INTO tablename (Filename, FileSize, File)

VALUES ( '" . $parameters['Filename'] . "', '". $parameters['FileSize'] . "', '" . $parameters['File'] . "' ) ") or die (mysql_error());

}

Now everything is getting uploaded, only the weird thing is, for instance if I upload an 370KB file, it's 490KB in the Database....

I don't know how this happens, and if this is normal?

Now to save it in my fileserver :

$query = mysql_query("SELECT File FROM tablename WHERE ID = '1' ") or die (mysql_error());

$fetch = mysql_fetch_array($query);

$data = $fetch[0];

file_put_contents("user_123.pdf", $data);

When I open this file that is getting saved now in my fileserver, I get this error : "user_123.pdf cannot be opened because this filetype is not supported or because it is damaged."

I'm fairly new to Blob types, and I know that storing files on your server is sometimes better, but I have to use Blob times, since I was asked to do so.

If anyone could help me out here, it would be greatly appreciated.

网友答案:

Solved it, had to use base64_decode($data) on my blobtype.

分享给朋友:
您可能感兴趣的文章:
随机阅读: