PHP saving from MSSQL db Base64 image to jpg
Hoping someone can help. We're running PAC's SecureNet software here and i'm trying to tie in a webcam, so that when we take someone's photo, it is already inside the software. Using MS Server Management Studio I can see the photo field. The software currently saves the image as Base64.
For our own systems it would be really handy to have access to these images. So I've got a PHP script which can see the PAC database and extra the photo code. I can display this easily enough, although I barely understand it.
My problem comes when I try to save the file. It saves a typically 120kb jpg as a 900kb jpg. And it's a jpeg which Word can use but can't be opened in Photoshop?
We're about to hand out 300 photo IDs to our sixth form, so I'm trying to streamline this process as much as possible. Here's my code:
I've tried using imagecreatefromstring() but I can't seem to pass the correct data. Does anyone have any idea what I'm doing wrong?
$data = "data:image/jpeg;base64,".base64_encode($temp_photo);
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
$success = file_put_contents($output_file, $data);