Upload a file with App Inventor 2 to a server through PHP

流过昼夜 提交于 2019-12-24 03:03:30

问题


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):


回答1:


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.";
?>


来源:https://stackoverflow.com/questions/28756349/upload-a-file-with-app-inventor-2-to-a-server-through-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!