How to upload to PHP server

0 favourites
  • 1 posts
From the Asset Store
You can upload screenshots and photos to your server very easily.
  • After weeks searching and not finding anything, I thought and found a solution, no gambiarra of turning images I base64 or something like.

    It's simple, you add File Choose and a button.

    Add the Web plugin and when you start the layout you put it to execute as javascript command:

    "

    $(function () {
    
     var form;
     $('#fileUpload').change(function (event) {
     form = new FormData();
     form.append('fileUpload', event.target.files[0]); 
     //var name = event.target.files[0].content.name; extenção
     });
    
     $('#btnEnviar').click(function () {
     $.ajax({
     url: 'URL', // URL of your server
    
     data: form,
     processData: false,
     contentType: false,
     type: 'POST',
     success: function (data) {
     // return
     }
     });
     });
    });"
    

    Remember to set the ID of the file chooser to 'fileUpload' and from the button to 'btnEnviar' or another of your own, but do not forget to change the js code as well.

    In php:

    <?php
    
     if($_SERVER['REQUEST_METHOD']=='POST'){
     $file_name = $_FILES['fileUpload']['name'];
     $file_size = $_FILES['fileUpload']['size'];
     $file_type = $_FILES['fileUpload']['type'];
     $temp_name = $_FILES['fileUpload']['tmp_name'];
     
     $location = "../imagens/";
     
     move_uploaded_file($temp_name, $location . $file_name);
     
     echo "done";
     
     }else{
     echo "Error";
     }
     
    ?>
    

    That's it, it's very easy to.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)