Tag Archives: php

What if there’s no way to upload a file to a server?

More than once, the question has been asked how to upload files to a server from a mobile device. An important problem is that sockets aren’t supported by default and a bug on Android preventing pictures from being saved to an album or attached to an e-mail. You might use Dropbox or a similar service, but requiring your customers to use an additional service doesn’t give a very professional impression.

I have created a very simple LiveCode+PHP library, which uploads small files to a server. It might also work with bigger files, but I haven’t tested this yet. This library works on any Android/iOS device and also works on desktop machines with any operating system.

There is no documentation yet and the current version is quite crude. No security has been implemented yet. If you’re curious, you might want to have a look. If you need an off-the-shelve solution, then maybe not yet.

The library can be downloaded at http://qery.us/43p after making a donation (or if you made a donation less than 1 year ago). Currently, our server doesn’t send e-mails automatically and you may have to wait up to 24 hours to get access to the private downloads.

Make PHP and MySQL communicate on Mac OS X 10.6 Snow Leopard

I write this blog post because every few months I need make PHP and MySQL work on Mac OS X and every time I have to figure it all out again. Time to write it down…

The following instructions consider Mac OS X 10.5 and 10.6 (Leopard and Snow Leopard).

Almost always people start shouting “MAMP!” as soon as people have problems with PHP and MySQL on Mac OS X. It is nonsense to install MAMP on a Mac because almost everything is already installed on your Mac. Why would you install all necessary server software twice? It just takes away hard disk space. You really don’t need to use MAMP. All you need is to figure out how to configure PHP and MySQL.

Obviously, before PHP can work with MySQL, you need to install MySQL. You can download MySQL for Mac OS X here http://www.mysql.com/downloads/mysql/ . Install MySQL and don’t forget to install the preferences panel that comes with it.

Now you can activate PHP. Type command-shift-G in the Finder and type /etc/apache2/ in the little window that appears. Click on Go en find the file httpd.conf in that folder. Copy this file to the desktop and create a backup copy named httpd.conf.old.

Open the file httpd.conf in TextEdit and search for the line containing

#LoadModule php5_module libexec/httpd/libphp5.so

Remove the # and save the file. Copy the modified file to /etc/apache2/ en cofirm if you are asked whether you want to replace the existing file.

When PHP tried to communicate with MySQL, it uses a socket file to contact MySQL. PHP expects o find this file in /tmp/mysql.sock while MySQL puts the file into /var/mysql/mysql.sock. It has been like this for year and I really don’t understand why the two parties involved don’t solve this.

The “temporary”solution is to tell either PHP or MySQL to create or search the socket file somewhere else. The easiest way (in my personal opinion) is the following.

1) open TextEdit and type the following four lines:

[mysqld]
socket=/var/mysql/mysql.sock
[client]
socket=/var/mysql/mysql.sock

2) Save this text file at the location: /etc/my.cnf

You may be unable to save the file in /etc right-away. In this case, you can save the file on your desktop first. Type command-shift-G (in the Finder) and type /etc in the little window that appears. If you click on Go, you will see a Finder window displaying the content of folder /etc. Now you can copy the file my.cnf to the folder /etc. You may need to enter your admin name and password when you copy the file.

Now you need to turn off and on Web Sharing in the System Preferences. You may need to turn off and on MySQL too, which you can do in the MySQL preferences panel.

PHP should now be able to use MySQL.