Android Question Send file to server using httputlis2 postfile

Discussion in 'Android Questions' started by Devv, Mar 24, 2015.

  1. Devv

    Devv Active Member Licensed User

    Hello guys i'am trying to send a file to my server using php
    i tried the following

    Code:
    <?php
       $FileName = $_GET[
    'FileName'];

       
    if (!$FileName)
          $FileName = 
    "FileName";

       
    if (strstr($FileName,"php"))
          
    return;

       $PostData = file_get_contents(
    "php://input");

       $
    File = fopen($FileName,"wb");

       fwrite($
    File, $PostData);
       fclose($
    File);

       echo 
    "ACK";
    ?>
    the following code is working but i'am always getting the file names as "FileName"

    WHY php is not recognizing the file name ??
    can i send the file name with the file as an extra parameter ?

    PS: i'am using httputlis2 post file to send it to the php
     
  2. DonManfred

    DonManfred Expert Licensed User

    Cause you dont give a filename with a postfile request.
    You need to use a multipartpost to give a file AND a (or even more) value with one postrequest.
    See my signature for a Example
     
    Devv likes this.
  3. Devv

    Devv Active Member Licensed User

    thanks for fast replay DonManfred
    the files i'am working with is less than 50 KB.
    sorry for this silly question but i'am a noob
    multipartpost: does mean sending the file part after part each part as one http post
    or it does mean that a single http post with more than one parameter ?

    anyway is their is a difference in the request time if using normal or multipart post ?
     
  4. DonManfred

    DonManfred Expert Licensed User

    See my example. I´m using two files in ONE uploadrequest. You can put more... You need to handle the files then via the $_FILES array like in an normal webpage-formular-request.
     
  5. DonManfred

    DonManfred Expert Licensed User

    not really... a few bytes more to send. And you need to handle the given vars in another way than you did in a postfile-request
     
  6. DonManfred

    DonManfred Expert Licensed User

    yes
     
  7. Devv

    Devv Active Member Licensed User

    Thanks bro , i'am seeing your script now
    so making a little change to my script is not possible to send a string (file name) with it ?
    i have to change the whole sender and receiver code right ?
     
  8. DonManfred

    DonManfred Expert Licensed User

    No using postfile

    yes.

    You can store the filename in this code when sending...
    Code:
    Dim fd As FileData
        fd.Initialize
        fd.Dir = 
    File.DirAssets
        fd.FileName = 
    "snap1.png"
        fd.KeyName = 
    "Aufnahme"
        fd.ContentType = 
    "application/octet-stream"
        files.Add(fd)
     
    raphaelcno and Devv like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice