Android Question Send file to server using httputlis2 postfile

Devv

Active Member
Licensed User
Longtime User
Hello guys i'am trying to send a file to my server using php
i tried the following

B4X:
<?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
 

DonManfred

Expert
Licensed User
Longtime User
WHY php is not recognizing the file name ??
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
 
Upvote 0

Devv

Active Member
Licensed User
Longtime 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
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 ?
 
Upvote 0

Devv

Active Member
Licensed User
Longtime 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 ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
so making a little change to my script is not possible to send a string (file name) with it ?
No using postfile

i have to change the whole sender and receiver code right ?
yes.

You can store the filename in this code when sending...
B4X:
    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)
 
Upvote 0
Top