Save snapshot on server

Get help using Construct 2

Post » Mon Dec 16, 2013 6:26 pm

Hello,

I've been playing around trying to figure out how to save a snapshot on my server. I know this can be done with PHP, just not sure how since I'm not a programmer myself. I have tried following @muschalski's tutorial, resulting a blank JPEG located at /licagr-photos on my server.

Basically, when a button is clicked or tapped it will take the snapshot, contact a PHP script located at my server (/upload.php) via AJAX (post to url).
I just need the PHP script. Sadly, I cant pay you since I'm poor, though I can give you credit in the finished product, including a link to your profile/social network if you want :)

If you have any questions, throw 'em at me.
Happy holidays!

Chris
B
5
Posts: 17
Reputation: 237

Post » Mon Dec 16, 2013 7:35 pm

Hello.

This should be the PHP file that you need.

It worked for me, make sure you have a folder where the PHP file sits named "user_photo", or change the directory name.


<?php

chdir('');

$img = $_POST['photo'];
define('UPLOAD_DIR', 'user_photo/');


$img = str_replace('data:image/jpeg;base64,', '', $img);
$img = str_replace(' ', '+', $img);

$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.jpeg';

$success = file_put_contents($file, $data);

?>GameThirsty2013-12-16 19:40:11
B
17
S
6
Posts: 348
Reputation: 2,608

Post » Mon Dec 16, 2013 8:42 pm

Thanks for sharing your code, I will try it out tommorow!
B
5
Posts: 17
Reputation: 237

Post » Tue Dec 17, 2013 5:42 pm

[QUOTE=GameThirsty] Hello.

This should be the PHP file that you need.

It worked for me, make sure you have a folder where the PHP file sits named "user_photo", or change the directory name.


<?php

chdir('');

$img = $_POST['photo'];
define('UPLOAD_DIR', 'user_photo/');


$img = str_replace('data:image/jpeg;base64,', '', $img);
$img = str_replace(' ', '+', $img);

$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.jpeg';

$success = file_put_contents($file, $data);

?>[/QUOTE]

I tried out your code, unfortunately also resulting a blank JPEG.
I made a sample .capx of what I've done, so if you have time to check it out, that would be awesome.

Links for my server:
upload.php: aalic1nrf.3owl.com/upload.php
photo directory: aalic1nrf.3owl.com/licagr-photos

The PHP code is the exact same as you posted, except I changed the directory folder.
By going to /upload.php it actually says;

Warning: chdir(): open_basedir restriction in effect. File() is not within the allowed path(s): (/home/u393737372:/usr/lib/php:/tmp) in /home/u393737372/public_html/upload.php on line 3

I guess that does not matter since it's just a warning?

.CAPX download: http://www.mediafire.com/download/2m5of2be0gvflba/snapshot.capxc01052013-12-17 19:03:51
B
5
Posts: 17
Reputation: 237

Post » Tue Dec 17, 2013 8:06 pm

You are probably getting a blank image, because the AJAX request is supposed to post "photo" to the PHP file. When you post the URL it does not have photo. The PHP file then doesn't know what image to give it.


See, part of the PHP file requests this:

$img = $_POST['photo'];

Change your CanvasSnapshot to this:



Uploaded with ImageShack.usGameThirsty2013-12-17 20:11:24
B
17
S
6
Posts: 348
Reputation: 2,608

Post » Wed Dec 18, 2013 6:30 pm

For some reason it keeps uploading blank images, although I did thange CanvasSnapshot to "photo="&CanvasSnapshot instead.

Could there be something wrong with my server? Something I have to setup? I actually changed PHP version from 5.3 to 5.4, didn't make a difference though...

I checked upload.php and it is the EXACT same as yours, directory is just licagr_photos.

This is just weird. Any ideas?
B
5
Posts: 17
Reputation: 237

Post » Wed Dec 18, 2013 6:49 pm

Is this your own server?

There might be a permissions issue inside your directory for read and write access.
B
17
S
6
Posts: 348
Reputation: 2,608

Post » Wed Dec 18, 2013 7:02 pm

It's hosted by 3owl.com, so it's not a private server.

If there would be read and write issues, what could the title be? I mean, I have a lot of options when going to my server dashboard, such as FTP Access, DNS, PHP options etc.
B
5
Posts: 17
Reputation: 237

Post » Sun Jul 13, 2014 10:00 pm

hello there for me is working. thanks so much!

in "Snapshot canvas" the default value is PNG extencion. just change to JPEG like in php file and it works!!!
yolinux
B
18
S
5
Posts: 19
Reputation: 1,545


Return to How do I....?

Who is online

Users browsing this forum: mrkaio, Zav and 3 guests