Archief van de categorie ‘Playground’

28 mei 2010 - Door Korstiaan

File upload progress bar with PHP+APC and JavaScript

Normally when we give a user the possibility to upload files, we give them a nice SWF-based upload solution in order to provide some feedback about the progress. Recently we discovered that PHP has built-in support for this, with a little help from APC (an opcode cacher and memcached alternative).

This knowledge resulted in a library which does all the work needed for this automatically. All you need to do is initiate our JavaScript class, and all inputs are handled automatically. The library consists of a MooTools-based JavaScript class, a PHP file which handles all the AJAX requests and a CSS file.

Unfortunately this library (and APC support) doesn’t work on a default PHP install. The following things are required:

After restarting Apache, download the library, which can be found at http://www.hoppinger.com/playground/progress.zip.  Next step is to upload progress.php, progress.js and progress.css,  include progress.js, progress.css and MooTools (tested with version 1.2.3) in the HTML <head>, and initiate the uploadProgress class for every form you want files handled by this.

Example:

<script type="text/javascript" src="/javascript/mootools-1.2.3-core.js"></script>
<script type="text/javascript" src="progress.js"></script>
<script type="text/javascript">
window.addEvent('domready',function()
{
 $$('form.upload').each(function(o_form)
 {
  o_form.fileUpload = new uploadProgress(o_form,{
         's_actionHelper' : '/playground/progress/progress.php',
         'i_interval' : 1000
             });
 });
});
</script></script>
<link type="text/css" rel="stylesheet" href="progress.css">

This makes the library work for every form with class “upload”.  As you can see, the class has two parameters, the first is the form object and with the optional second parameter you can set a few options:

  • s_actionHelper – the location of progress.php
  • i_interval – the polling interval for progress.php in milliseconds

The layout of the progressbar can be changed by editing progress.css.

When a user uploads the file, and all went well you can find the data JSON’ed in $_POST with the same  name as the original <input>.  If something went wrong (e.g. when the user doesn’t have JavaScript), the file information can be found where you would normally look, in $_FILES.

An example can be found here: http://www.hoppinger.com/playground/progress/index.php

Please note that this is the first version (0.1). Contact me (korstiaan [at] hoppinger.com or the comments)  if you are missing features and/or found a bug.

21 mei 2010 - Door Martijn

Cooliris media gallery

Een leuke tool om eenvoudig in je site te plaatsen en bijvoorbeeld je foto’s uit je Flickr account aan je bezoekers te laten zien. Onderstaande uitvoering is een Flash variant, er is echter ook een plugin (voor de meeste browsers) waarmee je bijvoorbeeld je lokale fotoalbums op een verjaardag of feestje aan je familie of vrienden kunt tonen.

Meer informatie erover is te vinden op: http://www.cooliris.com

1 april 2010 - Door Luís

HTML5 APIs – Geolocation API

HTML5 is onderweg en brengt nieuwe eigenschappen/kenmerken (features) met zich mee zoals form controls, API’s, multimedia-integratie, nieuwe structuur en semantics.

Een van de nieuwe APIs is de Geolocation API.

Wat is Geolocation?

Geolocation is een techniek om de geografische locatie van een bezoeker te bepalen door middel van het IP-adres en andere middelen.

Wat zouden de mogelijke toepassingen voor de Geolocation API zijn?

Internet is niet meer alleen toegankelijk via de PC, maar ook via de mobiele telefoon. Met Geolocation kan je content en diensten zien/krijgen die gebaseerd zijn op locatie (content location awareness).

Location Aware Application (Applicatie gebaseerd op locatie)

Denk bijvoorbeeld aan een on-line landelijke krant. Die kan nu regionale artikelen aanbieden die gebaseerd zijn op de locatie van haar gebruikers. Een ander voorbeeld: stel dat je wil weten welke restaurants er zijn in de omgeving waar je je op dat moment bevindt maar je weet het adres niet. Via je mobiele telefoon ga je naar een website die dit soort diensten aanbiedt en kun je zonder veel te doen een overzicht krijgen van restaurants in je buurt.

Demo/Voorbeeld

Geolocation is simpel te implementeren. Met deze simpele javascript code kun je je positie achterhalen: navigator.geolocation.getCurrentPosition();

Hierbij een demo (met google maps):

<html>
...
<script type="text/javascript">
function initialize()
{
// Get the current position with W3C Geolocation API
navigator.geolocation.getCurrentPosition(getLocation);
// Pass the latitude and longitude to Google Maps
function getLocation(pos)
{
var position = new GLatLng(pos.coords.latitude,pos.coords.longitude);
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(position, 16);
var marker = new GMarker(position);
map.addOverlay(marker);
map.setUIToDefault();
}
}
</script>
…
</html>

Dit is een simpele demo om te laten zien hoe eenvoudig het is de Geolocation API te gebruiken in webpagina’s. Geolocation is niet 100% nauwkeurig zoals GPS als je op straatniveau wil gaan, maar biedt veel opties wat betreft content gebaseerd op locatie als je bijvoorbeeld op stadsniveau gaat.

Bekijk de demo zelf (werkt alleen op iPhone en Firefox 3.5+) :
http://www.hoppinger.com/playground/html5/geolocation/

Wie is Luís?

Ik ben een student van Grafimediatechnologie en ben bezig met afstuderen bij Hoppinger. Als afstudeerproject ga ik onderzoek doen naar platform-onafhankelijke mobiele webapplicaties voor smartphones. Hoe kunnen webbedrijven platform-onafhankelijke mobiele webapplicaties bouwen met behulp van webtechnologie zoals HTML, CSS, Javascript enz.