I have developed a specialized Android application whose operation relies partly on files that are produced by a third party. These files basically contain configuration script that the application needs in order to work with an external hardware device. Different variants of the hardware have a unique script file, and updates and therefore new scripts are quite frequent. To date, it has been sufficient to just bundle the script files in with the application and push out frequent application updates when new scripts become available. However, a far more ideal solution would be to have the application grab an appropriate file from a web service if it isn’t available locally on the device.
At the moment no online web service exists for obtaining these files, so it is something I will create myself, and I will manually place the files onto the server.
To find the appropriate file, the application needs to match a particular string inside the file. Therefore, given a text string (which would be provided in the query string – something like findfile.php?identifier=fredbloggs), the web service needs to search through all held files and return one that contains the string inside, or otherwise an indication that the resource isn’t found.
I haven’t done much PHP before, but my intention was to knock together a simple PHP script that, when requested, initially reads through and caches the identifier strings from all scripts held on the server, and then serves back the one that contains the matching identifier string.
My question is, is there a better, simpler, or more ‘fashionable’ approach to solving a problem like this these days? For example, is there a way I could use Dropbox, or is there some other existing online storage service that already provides a handy API that does all this, to save me cooking up my own PHP service?
Instead of looking for a simpler/fashionable way, I suggest you always plan for extend-ability.
You should probably use a MySQL database which stores the keyword and path to corresponding file to serve. (This db can be populated manually / or run a script on the server manually). When you need to get a script, you can invoke a web service which would query the db, get the correct file, and serve it. This is recommended also because in the future you might have some other data related to the scripts to look up (like scripts version number, maybe?). Grepping through all the available scripts would be inefficient.
Handling PHP and mySQL is really simple, running through a w3schools course can get you across.