Upload a file with App Inventor 2 to a server through PHP
in the URL you should only transfer the filename without path, e.g. app_inventor_1424997354199.jpg
in the PostFile
block you should use the complete path, e.g. file:///storage/emulated/0/Pictures/app_inventor_1424997354199.jpg
then on the server, try Scott's solution
<?PHP
$data = file_get_contents('php://input');
if (!(file_put_contents($_GET['fileName'],$data) === FALSE)) echo "File xfer completed."; // file could be empty, though
else echo "File xfer failed.";
?>
Comments
-
Franck Dernoncourt almost 2 years
I am trying to upload a file with App Inventor 2 to a server through PHP. I followed the Photo Booth Android app tutorial, however server-side, myPhoto.jpg contains the filename, not the picture's content (e.g. myPhoto.jpg contains something like "file:///storage/emulated/0/Pictures/app_inventor_1424997354199.jpg"). How can I fix it?
The code I use:
tempSaveFile.php :
<?php $dataToWrite = $_REQUEST['fileName']; $fileName = "myPhoto.jpg"; file_put_contents($fileName, $dataToWrite); ?>
I am aware of Taifun's tutorial but since in my php.ini
always_populate_raw_post_data = On
I would prefer to avoid having to install anything.Scott's tutorial seems to do something similar (with App Inventor 1):
-
Franck Dernoncourt about 9 yearsThanks, it works! Also in postfile.php in your tuto, which is more complete (I like the error handling), I replaced
$data = php_compat_file_get_contents('php://stdin');
by$data = file_get_contents('php://input');
, it made it work (without having to use the PEAR package)