Save snapshot on server

0 favourites
  • 9 posts
From the Asset Store
Create your own wss server and ws server with ssl and without ssl.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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);

    ?>

  • Thanks for sharing your code, I will try it out tommorow!

  • 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);

    ?>

    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: mediafire.com/download/2m5of2be0gvflba/snapshot.capx

  • 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.us

  • 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?

  • Is this your own server?

    There might be a permissions issue inside your directory for read and write access.

  • 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.

  • 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!!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)