Post Data Url returns a 0x0 png

Get help using Construct 2

Post » Fri Nov 07, 2014 8:46 pm

I have a code that gets data(png,jpg and stuff) and save it as a file.
Code: Select all
<?php
   // requires php5
   header('Access-Control-Allow-Origin: *');
   define('UPLOAD_DIR', 'static/images/');
   $img = $_POST['img'];
   $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 to save the file.';
?>


The host is DataServer.Airwavestudio.co.uk/<pathhere> the path here is removed as it can be used to post stuff if gotten hold off.

Image
raw: "type='base64'&image=" & URLEncode(RegexReplace(CanvasSnapshot, "data:image/png;base64,", "", ""))
but everytime it gets posted it makes a 0x0 png file.
So what am I doing wrong?
B
10
S
1
G
1
Posts: 63
Reputation: 840

Post » Sat Nov 08, 2014 2:59 am

Your Data field doesn't represent valid variable for Post, it just returns nothing, look your php script:

$img = $_POST['img'];

It should be

$img = $_POST['image'];


You don't need to add useless functions because your PHP script already comes same functions as replace function.

Data field, should be:

"image="&CanvasSnapshot

image variable represents post data.

It's simple, that's all.



If you aren't sure, you might consider to get this template.

https://www.scirra.com/store/royalty-fr ... -image-116
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421


Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 9 guests