jquery - Save base64 encoded image into the file in PHP -


i have following code :

<?php header('content-type: image/png'); $data = "ivborw0kggoaaaansuheugaaauaaaai8cayaaacwih5daaagaelkzjgrcxxoauipzztlg......";        define('upload_dir', '/home/desktop/image.png'); $img = $data; $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $file = upload_dir . uniqid() . '.png'; $success = file_put_contents($file, $data); print $success ? $file : 'unable save file.'; ?> 

here $data contain encoded string of image in base-64. want save image file. did previous code go through lot of tutorial in google it's not working.

can me going wrong.

thanks in advance.

define('upload_dir', '/home/xpointers/desktop/'); 

remember! apache webserver run own user rights (e. g. www-data). take care, apache user or group apache runs in have access desired directory. test can chmod 777 directory , see happens.

writing inside user directory not idea. if possible use neutral directory needed users can access.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -