HTTP POST - FILE

2,291 views
Skip to first unread message

robvoi

unread,
Jun 18, 2012, 5:55:26 AM6/18/12
to tas...@googlegroups.com
Hi,

I use the newest beta version.
Does the Data/File option in the PHP POST task mean that I can now upload files to a PHP site?
If so .. brilliant. But I don't get it to work.


What do I need to configure in tasker to upload a file stored on SD card?

Thanks a lot!
Robert

Pent

unread,
Jun 18, 2012, 8:50:42 AM6/18/12
to Tasker
> What do I need to configure in tasker to upload a file stored on SD card?

In the HTTP Post action, put the path to the file (starting with /) in
the Data / File field.

Pent

robvoi

unread,
Jun 18, 2012, 9:11:05 AM6/18/12
to tas...@googlegroups.com
Hi,

this is what I have done. But without the / in the beginning. When I put in the / I get an error "file not found". No error without it.

I use:
Server: DNS Name
Path: photo.php
Data/File: path to photo
Content Type: application/octet-stream

Not sure if the error is in the tasker task or on the web site.

Would be great if someone could post a working example.

Regards,
Robert

Pent

unread,
Jun 18, 2012, 9:25:26 AM6/18/12
to Tasker
> this is what I have done. But without the / in the beginning. When I put in
> the / I get an error "file not found". No error without it.

You definitely need the /.

Did you select the file with the magnifying glass icon next to the
parameter ?

Pent

robvoi

unread,
Jun 18, 2012, 9:34:49 AM6/18/12
to tas...@googlegroups.com
Yes, I did. An it put it in without the /. Did it again and now it is in. I don't get why or what I did wrong.
I see the request on the server but it complains with "Undefined index: userfile" in line 7 and 10.

Do you know what I do wong?

Thanks
Robert


<?php 
// In PHP kleiner als 4.1.0 sollten Sie $HTTP_POST_FILES anstatt 
// $_FILES verwenden. In PHP kleiner als 4.0.3 verwenden Sie copy() 
// und is_uploaded_file() anstatt von move_uploaded_file()

$uploaddir = '/var/www/robot/upload/';
$uploadfile = $uploaddir. basename($_FILES['userfile']['name']);

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    print "File is valid, and was successfully uploaded.";
    print "Here's some more debugging info:\n";
    print_r($_FILES);
} else {
    print "Possible file upload attack!  Here's some debugging info:\n";
    print_r($_FILES);
}
print "</pre>";

?>

dp106

unread,
Jun 18, 2012, 11:34:04 AM6/18/12
to tas...@googlegroups.com
Are you using the http post task or is there a new php post task in the beta version?

If you're using http post I don't think it is possible. You have to post the file using a html form on the website.

Pent

unread,
Jun 18, 2012, 11:49:16 AM6/18/12
to Tasker
You can specify a file to post in HTTP Post of the current beta.

Pent

robvoi

unread,
Jun 19, 2012, 1:19:23 AM6/19/12
to tas...@googlegroups.com
Yes, and I was hopen to upload photos with it. But I din't get it to work.
If someone did, a working example would be nice..

Robert

Sinan Ghareb

unread,
Aug 16, 2012, 4:57:08 AM8/16/12
to tas...@googlegroups.com
Hi,

sorry to wake up an old thread, but I'm trying to figure out HTTP Post with files.

I have managed to send variables to a very simple php script:

here is the php script:

<?php

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");


ob_start();

print_r($_FILES);

print_r($_POST);

print_r($_REQUEST);

$string = ob_get_clean();

fwrite($fh, $string);

fclose($fh);

?>

The script prints all types of form posting methods and writes it to
file.

This worked:
====================
Server:Port
192.168.1.64/android/test.php

Path:
<left it blank>

Data/File:

data1=item1
data2=item2

Cookies:
<left blank>

Timeout:
30

Content Type:
application/x-www-form-urlencode
============================

However when I tried to use a file, it didnt:
but I couldn't send a file?!

=================
Server:Port
192.168.1.64/android/test.php

Path:
<left it blank>

Data/File:


* I used the magnifying glass to browse to a file and this was the resulting path :*

/mnt/sdcard/wallpaper/image.jpg


Cookies:
<left blank>

Timeout:
30

Content Type:
* it changed automatically to:*
application/octet-stream
=======================
When I ran the task and then open the testFile.txt all I see is:

array()array()array()

What am I doing wrong? or is there a bug when we try to upload a file?

Thanks,
Sinan

Pent

unread,
Aug 16, 2012, 4:58:26 AM8/16/12
to Tasker
Sending a file is broken in the current stable release, try the beta I
posted above in this forum.

Pent

Sinan Ghareb

unread,
Aug 16, 2012, 5:08:42 AM8/16/12
to tas...@googlegroups.com
I see. Thanks

Sinan

Fun Homeautomation

unread,
Jul 1, 2013, 8:58:53 AM7/1/13
to tas...@googlegroups.com
Have this been fixed yet?
I can't find any beta available.
Have spend long time to get it work.
Thanks

Pent

unread,
Jul 1, 2013, 4:40:32 PM7/1/13
to tas...@googlegroups.com
Should be, assuming you're using Android 4.0+

Pent

Fun Homeautomation

unread,
Jul 2, 2013, 8:33:42 AM7/2/13
to tas...@googlegroups.com
Hi Pent, Yes I am on 4.0+, I can not figure out how to get it to work with a server script.

For php I have tried the FILES method but I don't know what reference name tasker use to send the file
$_FILES['reference_name']['nameoffile']

Pent

unread,
Jul 2, 2013, 11:08:49 AM7/2/13
to tas...@googlegroups.com
Sorry, I don't know anything about PHP.

Pent

Fun Homeautomation

unread,
Jul 2, 2013, 6:44:40 PM7/2/13
to tas...@googlegroups.com
Okey,
I think you need to know what name the (array?) file upload have, here is a sample html form that works for me to upload a file to my server.
The text in red are important to be same on the upload script and the formular so I guess if tasker POST with file type I think you already have set a name?

<form action="upload.asp" method="POST" enctype="multipart/form-data"> 
  Upload File: <input type="file" name="uploadname" /><br/>
  <input type="submit" name='submit' value="Upload" /> 
 </form>


Thanks

Fun Homeautomation

unread,
Nov 12, 2013, 4:44:11 AM11/12/13
to tas...@googlegroups.com
Has anyone got it working yet?

I installed HTTP Snoop server to see the posted data. I have only paste few lines of data from the posted image. I was hoping to find the "file name" but not.

Request information
===================================
Version: HTTP/1.1
Hostname: 192.168.2.221:8008
Request uri: /

Header 1: Content-Type = application/octet-stream
Header 2: User-Agent = Tasker/4.1u3m (Android/4.2.2)
Header 3: Connection = close
Header 4: Host = 192.168.2.221:8008
Header 5: Accept-Encoding = gzip
Header 6: Content-Length = 1108765

Chunk: ����7 Exif  II*         �        �                   .      6   (       1      >   2    ^                 !        "        #        i�    r   %�    �   �                                   Acer                            A1-810                          H      H                                      2013:11:12 10:31:34 ��    �   ��    �   "�       '�    Q    �    0220 �    �   �    �   �    �
     �   �       �    �       �       
�    �    �    0100 �       �    �   �    
  �    _   �        �        �    �   �            6
@B   
   2013:11:12 10:31:34 2013:11:12 10:31:34    
   ^   d   d   d  
           N      N      E      f             ~      �   @   �      �       ;            #      '              :� '                               ASCII   NETWORK                                                 2013:11:12                O      W   (
Reply all
Reply to author
Forward
0 new messages