Archive for August, 2006

PHP Ajax File Browser

New Version: Ajax File Browser 2.0 Beta, this version is no longer supported.

As the new buzz technology is developing, I realised I had no real evidence that I infact know how to use it. Coupled with the need for an intranet file server application, I decided to make an Ajax version of a Server File Browser.

Initial Screen Using the Sarissa ajax library, this handy application only has a page weight of 71kb! Directory listings are limited to 30 files/folders per page, so the ajax requests are quite quick. Additionally, the application has been tested on Firefox and IE 6 only. Please leave me a comment if you have bugs with other browsers.

All shared files can be downloaded, and are force saved. Meaning that you can even share your PHP source files, without letting them be compiled first.

Application Configuration

After downloading the application, unzip the contents to a directory on your webserver. This application has been designed for a host where the php document root is the root path of the application. So, it cannot work under a sub-directory of a domain or host name. You may want to look into sub-domains if this affects you.

The application requires no database (although may do so in future, to log downloads etc). There is only one configuration file, config.inc.php. In this file there are two main settings:File Browsing

  1. Shares
    Paths to directories on the server. They do not have to exist as a sub-directory of the application, they can exist relatively or absolutely. So long as the web service has permissions to the directory, you can browse it. This is the biggest reason why I had to write my own application. Others on the net simply didn’t allow complete server browsing. You must be careful not to share anything crucial or anything that will compromise server security. Once a directory is shared, all sub-directories will also be shared.
  2. Blacklists
    You can exclude certain directory names, file names, and even file extensions from being viewed. I was also going to include something about hidden or system files aswell, but I got lazy :)

Apache vs Other Servers

Included in this package is a .htaccess file for Apache servers. It’s main directive is to prevent PHP’s short open tags. If you have an error with the htaccess file (as some servers will not allow php values in them) then you will have to make arrangements to prevent the short open tag in another way. The short open tag will affect the XML documents returned with the Ajax calls. This directive is now irrelevant in v1.1

Demo and Download

Changelog

  • 2006-09-15 v1.1, No need for short_open_tag anymore

Technorati: ajax, php, javascript, web 2.0

Easy PHP Debugging

Wether I’m making complex web applications or a five page no brainer site, if I’m using PHP to do something the chances are something’s not going to work out exactly to plan. I quite often find myself spitting out this bit of code to see the contents of my variables: print_r($var);

While this works very well, it can be daunting to look at without some sort of formatting. Another dilemma I’ve found (only on those big projects) is that I can’t remember where I’ve put that piece of code in order to remove or comment it out.

Today I spent a short amount of time making my life easier. I’ve created a function that works very much the same way, but unlike print_r, this function can handle any type of variable. It’s extremely simple to use. Once the function is included to your application, just call it: echo dba($var1,$var2,$var3…);

The function will handle any amount of variables you throw at it. Here’s a sample output from one of my sites:

================================================================================
Debug Called:
/home/vhosts/trade/www/sub-contractors/materials.php on Line 448
/home/vhosts/trade/www/sub-contractors.php on Line 109

================================================================================
Argument #1: String
Hello World!
End Argument #1
================================================================================
Argument #2: Integer
9316729
End Argument #2
================================================================================
Argument #3: Float
4582.55
End Argument #3
================================================================================
Argument #4: Array
(
[0]
=> foo
[1] => bar
)
End Argument #4
================================================================================
Argument #5: db_mysql Object
(
[dbname:private] => trade
[id_link:private] => Resource id #15
[eh] =>
[query_counter] => 8
)
End Argument #5
================================================================================

Notice that the first part explains the trace of pages called before this function. On the first entry and line number you’ll find this function’s call. Subsequent pages are ‘parents’ of this page.

It’s great! Where do I get it?

Technorati: php, programming