How do I upload file image

Get help using Construct 2

Post » Thu Oct 29, 2015 10:27 am

Hi,

I have the necessity to upload on my PHP web server 2 images.
The first is a preview of what the clients got (canvas snapshot)
The second is the original uploaded image.

I achieved this with something like
  • FileChooser plugin > Save file to local blob storage (like blob://http://myurl/myfile.png)
  • Sprite on screen > Set from URL (from local HTML5 blob storage)
  • Some check stuff (like filesize, mime etc...)
  • Canvas snapshot
  • Ajax Post with "Canvas="&CanvasSnapshot&"&FileName="&CustomName
  • PHP file that handle the file

Code: Select all
if (isset($_POST['Canvas']))
   {
      $img1 = $_POST['Canvas'];
                $img1 = str_replace('data:image/jpeg;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
                $data1 = base64_decode($img1);
                 [...]
                 $success = file_put_contents($file1, $data1);
   }




Now I have the file in the HTML local blob storage, the canvas preview on my server BUT
How do I upload the original, uncompressed, file?

Thank you
Luca ConTato [RisingPixel]
Image
B
22
S
8
G
2
Posts: 117
Reputation: 2,909

Post » Thu Oct 29, 2015 2:11 pm

...I've made a workaround with a custom js extra file

Code: Select all
   function uploadfilex(url, filename)
   {   
      var uploadfiles = document.querySelector('#imageuploader');
      var file = uploadfiles.files[0];
      file.name = filename;
      
        var xhr = new XMLHttpRequest();
        var fd = new FormData();
        xhr.open("POST", url, true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                // Every thing ok, file uploaded
                console.log(xhr.responseText); // handle response.
            }
        };
        fd.append('upload_file', file);
      fd.append('name', filename);
        xhr.send(fd);
    }
Luca ConTato [RisingPixel]
Image
B
22
S
8
G
2
Posts: 117
Reputation: 2,909

Post » Sat May 06, 2017 10:58 am

How exactly to put this - Canvas="&CanvasSnapshot&"&FileName="&CustomName - in AJAX there is some boxes - Tag, URL, Data ?
It will be great to put some Screenshots for the stupid people like us haha - please help dude ....
B
3
Posts: 2
Reputation: 179

Post » Sat May 06, 2017 11:56 pm

Ooooooo this post i dead ..... :(
B
3
Posts: 2
Reputation: 179

Post » Tue May 09, 2017 10:16 am

Luca ConTato [RisingPixel]
Image
B
22
S
8
G
2
Posts: 117
Reputation: 2,909


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Yahoo [Bot] and 20 guests