I am attempting to write to an image file from a blob.
if($_POST[\'logoFilename\'] != \'undefined\'){
$logoFile = fopen($_POST[\'logoFilename\'], \'w\') o
If it's a file upload control, $_POST won't contain the information. You're looking for handling file uploads with $_FILES. (And more specifically, move_uploaded_file)
Given the new update, try the following:
//
// Export a image blob to a file using either the specific image name
// @blob : The actual image blob
// @fileName : Can be the explicit name (with an extension) or this can be
// just a generic file name and the extension (based on data
// type) will be appended automatically. This can also include
// path information.
// Exmaples:
// storeBlob('data:image/png;base64,...', 'myimage'); :: saves as myimage.png
// storeBlob('data:image/jpg;base64,...', 'img/new.jpg'); :: saves as img/new.jpg
function storeBlob($blob, $fileName)
{
$blobRE = '/^data:((\w+)\/(\w+));base64,(.*)$/';
if (preg_match($blobRE, $blob, $m))
{
$imageName = (preg_match('/\.\w{2,4}$/', $fileName) ? $fileName : sprintf('%s.%s', $fileName, $m[3]));
return file_put_contents($imageName,base64_decode($m[4]));
}
return false; // error
}