Is there anything special/different about uploading files from a mobile device vs. from the browser?
I'm making an application that requires users to upload a file through a mobile app... The mobile part will be done by another developer. I must simple prepare the functions so that they can be used by either the mobile application or web-browser.
Namely, do mobile apps (android) user the same $_POST, $_FILES, etc variables when interacting with the server?
$_POST and $_FILES are server side variables, constructed by the PHP SAPI. Totally irrelevant with regards to the type of HTTP client used.
PHP expects multipart/form data on a POST, so the app has be be compliant with that, but if the app uses a standard HTTP library to post the data (or the files), that should not be a problem.
And it's easy to test. Create a test controller:
<?php class Test extends Controller { public function action_index() { \Log::info(json_encode($_GET)); \Log::info(json_encode($_POST)); \Log::info(json_encode($_FILES)); } }
and have the android app post some data and upload a file to /test/index.
i use cordova: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>File Transfer Example</title> <script type="text/javascript" charset="utf-8">
function uploadPhoto(imageURI) { var options = new FileUploadOptions(); options.fileKey="file"; options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1); options.mimeType="image/jpeg";
var params = new Object(); params.value1 = "test"; params.value2 = "param";