Ack! This site is moving to since Comcast's efforts to improve their world's worst customer service ranking apparently include terminating web hosting for their existing customers.

Up With Php


As an addendum to my Stick In The Mud philosophy, I might add No Damn Clouds! as an offshoot. That led to the creation of this app for sharing files with my own dad-gum web server on my local LAN running a php upload script under apache. No third parties gathering marketing data on my local server :-).

Android Side

I haven't yet setup an official web site and registered as an android developer yet, so if you want to install this app, you need to turn on the Unknown Sources install option, then you can click on UpWithPhp-debug.apk to download the .apk file and click on the file in the Downloads entry to install it. [This version is pretty much finished, and probably won't change for a while.]

Once the app is installed, most anything that has a share button (like the gallery app in this screenshot):

Will bring up the sharing options list which now includes Up With Php as an option:

Of course, before the file sharing will actually work, you need to configure the app with the server (or servers) you want it to use for the upload. Do this by starting the app normally from the launcher, rather than using the share button.

Once you have multiple profiles defined, you can select the profile to use by clicking on the name. If you want to delete a profile, you can long click on the name (but it you want to delete the current profile, you need switch to another profile first).

To define a new profile or change an existing one, click the Edit Current Profile button to bring up the preferences screen. Here you can redefine the upload URL and say if you want to convert the filenames to lower case:

If you edit the Profile Name, you will define a new profile.

The php Upload form-data field is very obscure and you'll probably never need to modify it, but if you want to upload files to a server that has different form data requirements, you can modify this field. The %1$s in the string is replaced by the filename of the upload.

Note that this tries to work on anything handed to it, but there are such a wide variety of things the share actions might do, I'm unlikely to have them all covered yet. Also, if I can't determine a filename, but can dig up some content, I generate a file name of the form UpWithPhp-yyyy-mm-dd-hh-mm-ss.dat (or sometimes .txt).

Desktop Side

The system where the files are uploaded needs to be running a web server and php (or something that acts like the php upload script below). On my Fedora desktop this means installing at least the httpd and php rpm packages from the Fedora repos. I'm sure Windows can run all this stuff as well, but I have no idea how to install it there.

The php upload script I am using is:


<table border=0 width=620><tr><td>
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/zooty/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";

echo 'Here is some more debugging info:';

print "</pre>";



You will need to customize at least the $uploaddir variable in there to say where you want the files to go. You also probably need to look at /etc/php.ini and consider changing some of the values in there to allow large files to be uploaded and make sure there is enough temp space:

post_max_size = 0
upload_tmp_dir = /zooty/tmp
upload_max_filesize = 20G

If you are running apache, adding this config file will allow you to browse the upload directory (obviously the directory name in here needs to match the name in the php script):

Alias /uploads /zooty/uploads
<Directory /zooty/uploads>
   Options Indexes
   Order allow,deny
   Allow from all

In keeping with the grand tradition of never being backward compatible, the latest 2.4 version of apache requires this syntax instead of the above old syntax:

Alias /uploads /zooty/uploads
<Directory /zooty/uploads>
   Options Indexes
   Require all granted

Of course you might also want to fiddle with the permissions to disable running cgi scripts and such in that directory if you don't trust everyone who has access to the web server :-).


All my apps at the moment are learning exercises (though they try to be useful as well). The stuff I've been learning about this is going in Chapter 7 of my Android book. There is a link to the source code there as well.

Page last modified Mon Mar 4 20:43:21 2013