Extend your capabilty

Ages ago when I was discovering the YUI Library, I stumbled upon Jack Slocum’s blog and his EXTension of the YUI.

Back then, I tried to implement the library but there was very little documentation and I gave up in frustration. Now, his library is at version 1 and he’s got a new site to go with it. Here’s a screencast to give you an idea of what it’s capable of.

There’s also a great starter tutorial there, and other tidbits. Personally, I’m going to be using the EXTensions more often (now that I know how).

Great stuff!

1 Comment

Change the maximum upload size with PHP

Depending on how you host your website (or application) there are different ways to change the PHP settings. In particular, the most asked about problem, changing the maximum upload size.

There are 3 settings PHP uses that limit your uploading ability:

  • post_max_size
    This is the combined maximum size of all files sent on the form. If you have 2 file fields on your form, the total filzesize of the 2 files must not exceed the post_max_size value.
  • upload_max_filesize
    This is the filesize limit of each individual file.
  • memory_limit
    PHP scripts have a memory limit, and generally speaking this can prevent some uploads from working. The limit should be set at a reasonable level, of course you won’t need 20mb for a simple ‘hello world’ script. Try slowly increasing this value if you find that uploads still aren’t working.

If you host your site remotely, you should check their documentation on how to change the PHP configuration settings. But if you’re not so inclined, and prefer a trial and error approach, here’s a summary of things to try:

Change php.ini directly

If you host your site on a server that you have access to, you can change your php.ini file directly. This is the easiest approach. Your php.ini file should exist in the PHP installation directory. Open it in your favourite text editor and search for these lines and change them:

memory_limit = 8M
post_max_size = 8M
upload_max_filesize = 2M

You may need to restart apache for the changes to take effect.

Changes to .htaccess

.htaccess files only apply to Apache webservers. They are files that append and change certain values that apache uses and they are placed in the root folder (and all folders beneath will use those settings). If apache uses PHP as a Module, then you can add values to the .htaccess file:

php_flag file_uploads On
php_value memory_limit 8M
php_value post_max_size 8M
php_value upload_max_filesize 2M
 

Download this code: .htaccess.txt

If you try this approach, and your webserver displays a 500 interal server error, then PHP is not runing as a module and apache didn’t like the php_value entries. You will need to remove your changes.

Upload a php.ini file

This generally works if the changes to .htaccess method doesn’t. Some web hosts that use apache, also use PHP as a CGI. Then also, most times, this allows changes to the PHP configuration using a custom php.ini file that you can upload. You don’t want to include every setting available to PHP in your file. Only include the ones you want to change, and don’t forget the heading [PHP]:

[PHP]
; Whether to allow HTTP file uploads.
file_uploads = On
; Maximum amount of memory a script may consume (8MB)
memory_limit = 8M
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M 

Download this code: php.ini

Still not working

In the event these techniques didn’t work for you, check with your host’s documentation.

16 Comments

Ajax File Browser 3 Beta

Lately I’ve had some time to finally keep my promise to make a better AjaxFB.

I’ve also moved the downloads to Sourceforge, in a hope to better keep a track of bugs and other support issues.

The new version has a lot of neat stuff, and fixes a lot of bugs. Here’s a demo, give it a try.

The software is also available for download, but because it’s in beta (and even if it wasn’t) I take no responsibility for how you use or misuse the application or for any damage to or loss of files etc.

There is no documentation yet, but there are little hints here and there.

PS: I haven’t updated the official AjaxFB site yet, so you won’t find any information there.

40 Comments

YUI 2.2.0 Released

YAHOO have just released the 2.2.0 version of their famous YUI library. In actual fact, version 2.2.0 is really 0.12.2

They’ve changed their versioning, which will be much easier to follow. They’ve also included mega amount of extra features to their package. It’s far too much to mention, you’ll have to check it out for yourself.

No Comments

Suckerfish HoverLightbox Redux

A new version of the Suckerfish HoverLightbox has been released.

Check it out here.

No Comments

How to use Gzip to load your site faster

Lately I’ve been reading various random articles about some browsers ability to deflate zipped webpages, so that there is less bandwidth and faster loading times for websites. Although this ability has been around for a while, it’s only been lately that I have a need to use it.

To understand the concept of page compression and the support for it, visit this site. But in short, most browsers support it, including IE6 and 7 (according to this test page).

For those rare browsers that do not support compression, they just receive a non-compressed page. So effectively, you’d be nuts not to use compression on your site. There’s nothing to lose (apart from a slight server load increase, but I’m told Slashdot uses compression even with it’s large amount of site hits).

Here is a real world example of a page compressed with Gzip:

Gzip in action

Here I’ve compressed the html document, css and javascript files. Look at the total, that page is 75% smaller, and 75% faster to load in your browser.

This tutorial will only examine one particular way of implementing Gzip compression with PHP, but there is another way to accomplish it with Apache if you have administration access to your server.

How to implement Gzip compression in 5 minutes

Step 1: Enable zlib compression in php. You can do this many ways, just choose one:

  • Add a line to your .htaccess file:
    php_flag zlib.output_compression On
  • Add or change a line in your php.ini file:
    zlib.output_compression = On
  • Add a line to the top of your PHP scripts before any output:
    ini_set(‘zlib_output_compression’,'On’);

Now that you’ve done that (and particularly with the first 2 options), any file that is passed through PHP will be Gzipped if the browser supports it.

Step 2: If you want to compress other files, javascript, css, etc:

If your file does not pass through PHP before it is outputted, you can change the extension of the file to .php and it will be compressed. For this example I’ll use core.js.

  1. Rename core.js to something like core.js.php
  2. Open core.js.php in your favourite text editor and add this to the beggining of the file (before anything else) then save:
    <?php header("Content-type: text/js"); ?>

    Download this code: gzip_js_example.php

  3. Reference core.js.php in your html just as you would normally, the browser will see it as a JS file, not PHP:
    <script language="javascript" src="core.js.php" type="text/javascript"></script>

    Download this code: gzip_js_example.html

So to explain, we rename the file to make it a php file, so it is passed through the PHP compiler. Then we add a mime header line to the file, so that the browser knows what type of file it’s meant to be. Then we reference the file (if it’s a CSS or JS file for example) just as we normally would.

Remember to change the mime type to text/css for CSS files.

A quick note with this method. Only compress files that are specifically meant for a web browser (html, js, css, and xml). If you try this with a PDF file, for example, it works in browsers, but not when saved and displayed in Adobe PDF Reader.
If you’re finding that this method causes errors in your scripts, chances are that you haven’t got the zlib module installed with PHP.

Technorati: php, gzip, compression, browsers

No Comments