UploadFIle what need in server part??

135 views
Skip to first unread message

Jugador Player

unread,
Jul 22, 2021, 1:24:42 PM7/22/21
to DroidScript
UploadFile.. im trying to upload files using app.uploadfile().. but no work.
Some one how?
How work server side? .. i try this if (isset($_POST['submit'])) {

Thanks for help.

Justin blAblA

unread,
Jul 22, 2021, 1:45:03 PM7/22/21
to DroidScript
in php files are accessable via $_FILES

here a nice explanation of how it works: https://www.tutorialspoint.com/php/php_file_uploading.htm

just a sidenote from me: never allow uploads from unkown people/users and never forget validation and protection
uploading files to a webserver can cause major issues if  done wrong. 
(short:  never trust the client)

Justin blAblA

unread,
Jul 22, 2021, 1:47:39 PM7/22/21
to DroidScript
oops, the first sentence should be "in php uploaded files..."
Message has been deleted

Jugador Player

unread,
Aug 11, 2021, 9:03:34 AM8/11/21
to DroidScript
Well i use this file in my server part, tested and working with folder server permiss. All right..  But no work with app.UploadFIle.

<?php
    echo "Upload ";
    if(isset($_FILES['image'])){
        $errors= array();
        $file_name = $_FILES['image']['name'];
        $file_size =$_FILES['image']['size'];
        $file_tmp =$_FILES['image']['tmp_name'];
        $file_type=$_FILES['image']['type'];
        $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
        $extensions= array("jpeg","jpg","png");
        if(in_array($file_ext,$extensions)=== false){
            $errors[]="La extension debe ser del tipo imagen.";
        }
        if($file_size > 2097152){
            $errors[]='El archivo debe ser menor de 2 MB';
        }
        if(empty($errors)==true){
            move_uploaded_file($file_tmp,"images/".$file_name);
            echo "Hecho";
        }else{
            print_r($errors);
        }
    }
?>

<html>
   <body>
      <form action = "" method = "POST" enctype = "multipart/form-data">
         <input type = "file" name = "image" />
         <input type = "submit"/>
         <ul>
            <li>Sent file: <?php echo $_FILES['image']['name'];  ?>
            <li>File size: <?php echo $_FILES['image']['size'];  ?>
            <li>File type: <?php echo $_FILES['image']['type'] ?>
         </ul>
      </form>
   </body>
</html>


In DS i use this:

function OnStart(){
    var name = "dune-b0.jpg";
    var file = "Img/dune-b0.jpg";
    app.UploadFile( "http://myserver.com/uploads/upload.php", file, name, OnUpload );
}
function OnUpload( error, file, result ){
    if(error) app.Alert( "Upload Failed!" + "\n"+ error )
    else app.ShowPopup( "Response:\n" + result, "Upload Successful!" );
}



When i use app.UploadFile().. What is the type name sended by app.UploadFile?
In my case is 'image' ..  if(isset($_FILES['image'])){ ..

Please, some one can put a clean answer. With example will be better. Thanks, good day and health for all!

Alan Hendry

unread,
Aug 11, 2021, 12:19:31 PM8/11/21
to DroidScript
HI,
https://symdstools.github.io/Docs/docs/app/UploadFile.htm it uses a fully qualified path and file name
    var name = app.GetAppName() + ".js";
    var file = app.GetAppPath() + "/" + name;
    app.UploadFile( "https://yourwebsite.com/upload", file, name, OnUpload );
You could try that
Regards, ah

Jugador Player

unread,
Aug 11, 2021, 2:25:32 PM8/11/21
to DroidScript
Can you put an example, i know all that, is in the example included with droidscript.
In server side i think need know the name of the type. (writed in bold in my post at the begin of the php file).

PHP manual said this:
There is one global PHP variable called $_FILES. This variable is an associate double dimension array and keeps all the information related to uploaded file. So if the value assigned to the input's name attribute in uploading form was file, then PHP would create following five variables −
  • $_FILES['file']['tmp_name'] − the uploaded file in the temporary directory on the web server.

  • $_FILES['file']['name'] − the actual name of the uploaded file.

  • $_FILES['file']['size'] − the size in bytes of the uploaded file.

  • $_FILES['file']['type'] − the MIME type of the uploaded file.

  • $_FILES['file']['error'] − the error code associated with this file upload.


Or not need??
If no need, can explain how?, because i have not idea..
Thanks any way for your help and time!

Alan Hendry

unread,
Aug 12, 2021, 6:43:11 AM8/12/21
to DroidScript
HI,

As I understand it, the server should receive the file, 
and then your PHP code can read the 5 variables.

  • image/jpeg (.jpg, .jpeg, .jfif, .pjpeg, .pjp) [11]
So if your DS sends a jpg then $_FILES['file']['type']  should contain "image/jpeg"

Regards, ah
Reply all
Reply to author
Forward
0 new messages