- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could someone please tell me the best way to upload form data AND an image file to a PHP script while developing an XDK APP
After 2 weeks of going around in circles I'm no clearer.
I have managed to get form data uploaded fine using the XMLhttp functions - and JSON data - and created a PHP server which writes it to a database.
In trying to include an image file I have done everything;
- included it in the JSON upload - but although the debug console shows an object has been uploaded it doesn't 'understand' it in PHP (the $_FILES object has nothing in it)
- tried it as a 'multipart/form-data' upload with the data fields and the file appended together - can see it all in the console but my PHP still says 'undefined index' for $_Files and I can't get at the form data
- Been told by some to use Ajax functions - been told by other NOT to use Ajax and use xmlhttp -
End of tether ...please has anyone got some advice and preferably a tutorial or some sample code...for both sides...
Phil
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As of Android 4.4, the approach to select images via a FORM will not work successfully.
In order to enable communication with external third party websites and web services, you are required to enable the access list under the Project Panel > Build Settings.
I recommend that you include a * (asterisk) in the Access List field on the Project panel for your application. The asterisk allows for communication to any web server or site via your application or AJAX call. You can find the Domain List field with in the Cordova Hybrid Mobile App settings > Build Settings > (desired platform such as Android, iOS etc...)
For more information visit https://software.intel.com/en-us/xdk/articles/cordova-cli-412-domain-whitelisting-with-intel-xdk-for-ajax-and-launching-external-apps.
Example Project using AJAX, Cordova & PHP: http://monaca.mobi/en/blog/uploading-an-image-file-with-multipartpost-using-ajax-part-2/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for that Elroy. Not sure if the Whitelist article is relevant. I am using the Emulator and I am communicating with my server - and getting data fields - just not the file.
Is using the Ajax commands the way I should be doing things ?
I thought I'd read somewhere that xmlhttp was the preferred approach - but may be wrong as I'm now very confused with all the options.
Phil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
no hair left huh? well, I was in a similar situation a while back so I'll share my solution a bit
I have a messaging app written entirely with the Intel XDK cordova on both iOS and Android. It allows users to send pictures to each other. I change all the images into base64 encoded strings and store that as strings in the database. The advantages to this is that now you can just ajax or post them over to your server as strings and in html, they're actually easier to deal with. The disadvantage is that in string format, they are larger than their binary counterpart, thus, sending them up to your server take up more time. Also, on my server side, I'm running node.js and have enabled cors so from the client I can ajax stuff over. If you want to test the upload speed and see if the solution can work for you too, the app name is bluechatbox, it's free and doesn't require any login for you to test and you can uninstall it afterwards.
Hope this helps a bit and just keep trying, a solution is always just around the corner, happy coding!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Tony - don't think my skills are quite there yet - what I need is some sample code or a tutorial that does the whole thing so I can learn from it - getting very downhearted with the whole thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Elroy
Worked thru that tutorial and now think I've cracked it ...got data and a file uploaded...so I can carry on...cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@phil ~
Can you post a small example app that provides the ability to upload and the php code that accepts it?
Im sure it will help others out in the future :)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page