Do I Need To Upload File In Mit App Inventor
How to use the block in App Inventor
You probably likewise might exist interested in my App Inventor FTP Extension, which does not crave annihilation on the server side, it "just works"...
Scott already put together a nice example to post any file to a php server. Precondition to get this working is, to gear up the flag always_populate_raw_post_data to on on your server. Unfortunately some spider web hoster do not offer to modify that flag. You tin can observe it out with the following script how this is gear up on your server:
<?php phpinfo(); ?>
I also had this problem with my server, but then I found this solution on stackoverflow.com provided past powtac, which uses the PEAR::PHP_Compat package. I just copied the unzipped package to my server and modified the php script, see below to go this working. Woo Hoo! Cheers powtac and Scott!
If you can ready the flag always_populate_raw_post_data to on, simply apply Scott's example, in this case there is no demand for this workaround.
With this example you tin pick an image from your device and upload information technology to my server.
Install the PEAR package
- Download the PEAR::PHP_Compat package, I used the file PHP_Compat-one.6.0a3.tgz, which will exist stored on your computer
- Unzip the package (you lot can use any unzip program, for case seven nothing), a directory PHP_Compat-i.6.0a3 volition be created containing another zipped file PHP_Compat-1.vi.0a3.tar
- Unzip that file and another PHP_Compat-i.half dozen.0a3 directory and a file parcel.xml will be created
- Copy that inner directory PHP_Compat-ane.6.0a3 to your server into the same directory of the postfile.php script. This directory contains the 2 subdirectories Compat and tests and a file package-test.php
App Inventor Blocks
PHP Script
Version 2
I updated Scott's php script and added some basic security functionality from the script of Shival Wolf. Feel free to accommodate it to your needs. Precondition to get this working on your server: The PEAR::PHP_Compat package is available there.
<?php $ACCESSKEY="hole-and-corner"; header('Enshroud-Control: no-cache, must-revalidate'); if($_GET['p']==$ACCESSKEY){ require_once (dirname(__FILE__).'/PHP_Compat-1.6.0a3/Compat/Office/file_get_contents.php'); $data = php_compat_file_get_contents('php://input'); $filename = $_GET['filename']; if (file_put_contents($filename,$data)) { if (filesize($filename) != 0) { repeat "File transfer completed."; } else { header("HTTP/1.0 400 Bad Request"); echo "File is empty."; } } else { header("HTTP/one.0 400 Bad Asking"); repeat "File transfer failed."; } } else { header("HTTP/1.0 400 Bad Request"); echo "Access denied"; } ?>
Screenshots
Questions and Answers
Q1:I follow your tutorial but I have an error "500 internal server error" while "post file".
A: Are yous using GoDaddy? They are very restrictive about their settings. Allow me recommend 000webhost.com as spider web host, see imprint below. It is very piece of cake to work with them: just ftp the script and the PEAR package to a directory and information technology works without a hassle, and the all-time is: their service is free! You have to utilize php://input instead of php://stdin with them, meet also Q2 below.
Q2:I changed web hosting and now app response "File transfer failed." without error.
A:Equally you lot tin encounter from the php script, this is i of our own mistake messages. Delight bank check the log file on your server for php error messages. You can attempt to change the post-obit line
$data = php_compat_file_get_contents('php://stdin');
by the post-obit
$information = php_compat_file_get_contents('php://input');
Q3:I am getting error 1104 everytime I click on the Mail button (seems an error from android, before enter in PHP). If I click by the second time, I get the file sent via php. Does everyone know how to become rid of mistake 1104?
A: This seems to be an issue with Samsung devices, see also this thread in the forum. Y'all too tin find a workaround at that place. Thank you Kelson!
Q4: I constitute this project in which you can upload an image to your server. Is this free or do I take to change the code to my own server?
A: You can use my server for your tests, but should apply your ain server for permanently utilize. I volition delete the images from time to time from my server.
Q5:I want to know how to send an image from the app to a database in my web host. I don't understand if the image is finally going to the ftp or something else, because the page shows me "Access denied"
A: Yes, yous can apply this solution to send an image to your server. In the database merely add together the link to your uploaded epitome. If y'all follow the steps and install the php script on your web server, the image will be stored on your web server in the same directory yous install the php script. If you telephone call the php script which is used to upload the epitome to the server using a browser, you get the "Admission denied" bulletin. This is, because information technology actually does non make sense to open that page with a browser. Hope that helps!
Q6: I build this code, but when I desire to exam it, I get the error message "411 Length required. A request of the requested method POST requires a valid Content-length."
A: You are right, it does not work anymore on Strato. I now moved the example to 000webhost, run across also Q1 higher up in example yous like to employ that costless web host, too.
Btw. meanwhile I prepared an App Inventor extension, which can provide the length of a file, for more information see here.
Q7: I have downloaded "Postal service a file to your server in the net". It works fine with your server. With my server if I choose a png or jpg file I get error 503. My server is at One.com.
A: The error unremarkably means "Service temporarily unavailable". Encounter your web host support help most which server settings need to be inverse. Also this page might help to accommodate your settings or others, simply do a Google search.
Download
Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I promise it saved some of your time. If yes, and then you lot might consider to donate a small amount!
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.
Source: https://puravidaapps.com/postfile.php
Posted by: cajigassciespoins.blogspot.com
0 Response to "Do I Need To Upload File In Mit App Inventor"
Post a Comment