通过PHP将带有App Inventor 2的文件上传到服务器 [英] Upload a file with App Inventor 2 to a server through PHP
问题描述
我正在尝试使用PHP将带有App Inventor 2的文件上传到服务器.我遵循了照相亭Android应用教程,但是在服务器端,myPhoto.jpg包含文件名,而不包含图片内容(例如,myPhoto.jpg包含"file:///storage/emulated/0/Pictures/app_inventor_1424997354199.jpg"之类的内容).我该如何解决?
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?
我使用的代码:
tempSaveFile.php:
tempSaveFile.php :
<?php
$dataToWrite = $_REQUEST['fileName'];
$fileName = "myPhoto.jpg";
file_put_contents($fileName, $dataToWrite);
?>
我知道 Taifun的教程,但是由于在我的php.ini always_populate_raw_post_data = On
中,我更喜欢避免必须安装任何东西.
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.
斯科特的教程似乎做类似的事情(使用App Inventor 1):
Scott's tutorial seems to do something similar (with App Inventor 1):
推荐答案
,您应该只传输没有路径的文件名,例如app_inventor_1424997354199.jpg
in the URL you should only transfer the filename without path, e.g. app_inventor_1424997354199.jpg
中,您应使用完整路径,例如file:///storage/emulated/0/Pictures/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
然后在服务器上,尝试Scott的解决方案
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.";
?>
这篇关于通过PHP将带有App Inventor 2的文件上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!