How do I upload file image

0 favourites
  • 5 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • 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
    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);
    	}
    [/code:39ybmgh9]
    
    Now I have the file in the HTML local blob storage, the canvas preview on my server [b]BUT[/b]
    How do I upload the original, uncompressed, file? 
    
    Thank you
  • ...I've made a workaround with a custom js extra file

    	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);
        }
    [/code:difjxiww]
  • 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 ....

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ooooooo this post i dead .....

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