Friday, July 15, 2011

Cloud Computing - Final Module Post

What Is The "Cloud"?

Anyone not familiar with IT concepts could ask "What does cloud computing mean?". After a lengthy and interesting discussion in class, we came up with a summary that incorporates the concepts of cloud computing and highlights its shortcomings, pitfalls and benefits.

Cloud computing is a concept were you have hosted applications/platforms on remote computers. Utilising such a system will lead to:
  • no installations and upgrades required
  • a user system which is less subject to viruses
  • less control over your applications which may lead to problems when dealing with people
  • some loss of data depending on browser reliability


Platform Independance

The promises platform independence in cloud computing have long been mentioned. One can argue that platform independence in the cloud is an illusion since the cloud is still dependant on the browser (flash, legacy tech). The only thing that might come close is the creation of an identical interface across platforms. In today's word, and from a developer's point-of-view, if you need a webpage to be identical across all platforms, either use flash or you have to write browser-specific tweaks.



Strength & Scalability

The main strength and the forte of it's adoption is the ability of access from anywhere (freedom, but one cannot ignore that it is still dependant on the data connection). Cloud computing offers scalability: the cloud will not fix a badly designed architecture but in itself, but rather, it forms its roots in a scalable fashion



The Clients of Today

The cloud can be said to require thinner clients, but on the other hand, we have to remind ourselves of the giants strides in hardware leading in the same processing power that was available in your desktop PC 4 years ago to be in the palm of your hand. One argument that hold true is that with the cloud we are reducing layers (consolidation): think Chrome OS, eliminating the OS



Control, Control...

The cloud can be said to offer your less control over your data. Cloud operators are starting to take this into account, offering you a fair option to pull yourself out from their service while taking all your data with you (Google Liberation Front, Capsule CRM)



Security. Should I, Would I, Will I?

New security questions are asked with the cloud. One can argue that your password maybe a bottleneck in your security and that your data may-be intercepted in-transfer. There are systems nowadays to overcome these issues such as the system used by banks to Log-In into the online-banking systems. Proper encryption will also take care of the data transfer. The real problem actually is to convince the companies to utilise the cloud. A valid analogy is the question: "Were do you store your money?", and you'll answer, "The Bank, of course!". And why do you do that, and not keep the money hidden behind a brick? Because, a bank specializes in keeping the money secure. The same argument applies to cloud computing: you are offloading security liabilities and risks to a company which specializes in security.



Cost & Legal Issues

Cheaper. A simple statement which may hold true in cloud computing. You cannot get away with software piracy that easily since you are actually connected to the provider. On the other hand, costs could go up depending on licensing policies. Legal issues arise with cloud computing since different countries employ different laws.



A Few Examples

Some examples of cloud platforms
  • Citrix - provides desktop and server virtualisation
  • Office365 - your Microsoft Office, on the cloud, shared
  • Google Docs - Google's take on the cloud office
  • Google Apps - providing businesses with hosting and clouding options
  • iCloud - the upcoming service by Apple to integrate all your iDevices


Course Conclusion

This module was very enjoyable. We explored many technologies along the way including: HTML, CSS, JavaScript, SQL, PHP, XML, Web accessibility, Second Life, HTML5, CSS3, the Mobile web, Social Networking and Cloud Computing. Going through such an array of concepts, while writing a blog each week was quite an effective solution. It provided me with means to properly explain how I understood the concepts, left leeway for exploration and expansion while still remaining somewhat academic. I particularly enjoyed putting my take on the subject and highlighting problematic or frustrating issues (usually mutually expressed by my classmates). As a conclusion, the module was quite a well presented learning experience and I would recommend the weekly-blog as an assessment system to anyone.

Sunday, July 10, 2011

The Evolution of Social Networks


Where It All Started

For better or for worse, social networks have become part of our everyday life. Their relevance and importance and use has been increasing exponentially for quite some time. The origins of such networks can be traced back to the late 70s with the start of Usernets and BBSs (Bullettin Board Systems). BBSs were based on a centralised computer to which only one user could connect and have their say.

Through the late 80s, we saw the rise of Instant Messaging starting with IRC and ICQ. These allowed you to connect to a channel: chatroom, in which many other people were connected. ICQ was partly responsible for today's abbreviations such as LOL and BRB and emoticons.



The Profile Era

The idea of have a profile, were you could portray your self and adorn it with a photo can be partially attributed to the early dating sites. These allowed users to find and contact other people. From roots of BBSs stemmed the rise of online forums, which are still very much in use today.

In 1997, Six Degrees approached today's concept of a social network, were you can become friends with other users and create your own profile. This site was shut down in 2001. While Six Degrees was on the rise in 1999, LiveJournal came up with the concept of encouraging users to keep a blog which they constantly update. This is reminiscent of the basis of most social networks today.

By 2002, we started seeing a different and more somewhat more cautious approach to social networking through Friendster. This network is based on helping you make new acquaintances by considering friends of your friends and assuming similar interests. In 2003, we saw the introduction of Hi5. Hi5 was hugely popular in Malta back in 2005-2006 and it centred around your friends, and friends of friends. At the same time, MySpace was also blooming. It was appealing due to the fact that it allowed an infinite number of custimisation options to your profile, leading to some pretty eye-watering, blinking and horribly colour-schemed profiles. My Space was and still remains quite popular with the music scene. Also at the same time, LinkedIn introduced a business aspect to social networking. It is nowadays quite sought after by employers and employees alike.



Facebook; And The Rest Of Recent History

2004 saw the coming to fruition of Facebook. The company's story has been dramatised in the 2010 movie "The Social Network". Starting as an exclusive Harvard-only network, in 2006 it opened to the public and at the time of writing, they have just announced that Facebook has over 750 million users. The "wall" is Facebook's central feature, were one can keep up with their friend's activities. Facebook also started connecting technologies when it introduced instant messaging, apps and recently video calling for it's users.

Other social networks of mention are Flickr, which is popular with the photography scene. It focuses on the user's photos and one can add them to "pools" were the users of that "pool" can view them. There are other networks like Orkut, which is very popular only in certain countries and niche networks, mostly focusing on bookmarking like Delicious and Reddit. Other types of networks, or rather communities are the MMORPG communities like World of Worcraft, which is centred on their forums and in-game communications. There are also communities which focus on video content, ranging from YouTube, which allows you to post videos, to live streaming sites such as UStream.tv.



Today

Looking into the future, from 2007, Twitter has grown considerably. While not a social network in it's own right, but more of a short updates to your followers network, it has gained momentum. The recently launched (still in beta invite-only at the time of writing) Google+ service is also interesting. What Google have done is take the best of the other networks and add a flavour of their own. So they added a "wall" - like feature similar to Facebook's but also introduced the new concept of "circles". "Circles" allows you to group your acquantancies into categories, for example "Family" and "Photography". This will allow you to group or rather, categorise the information coming to your wall and it also therefore allows you to share particular materials with only a "circle" of friends.



Conclusion

Personally, right now, I make use of Facebook to keep up with my real-life friends, Twitter to keep updated with the latest and greatest and also trying out Google+. While Google+ is still pretty much full of tech-savvy people, I would like to see it grow but at the same time understand the simple question most people pose: "Why should I leave from the comfort of Facebook?". They can co-exist side-by-side, but this still remains to be seen.

Friday, July 1, 2011

The Mobile Web

The Evolution of the Mobile Phone

In this lecture we explored the evolution of the mobile phone. From simply devices which their sole task was to act as a portable home phone to today's multi-touch, multi-connected (time wasting) devices.

Some notable mobile phones in history:
  • Motorola Dynatac 8000X (1983) - The first portable mobile phone
  • Motorola Microtac 9800X (1989) - The first truly portable mobile phone, now featuring an address book, and the first flip-phone
  • Nokia 5110 (1998) - First mainstream mobile phone, featuring some in-built games and a 5 inch display
  • Nokia 3310 (2000) - Hugely popular phone with T9
  • Motorola RAZR (2004) - Hugely popular phone that set the standard for stylish and fashionable phones to come
  • Apple iPhone (2007) - Touch-screen goes mainstream, auto-rotation, integrated Wifi, Bluetooth and GPS


The Evolution of Mobile Phone Connectivity

Technology

Standards

Year Introduced

Data Rates

1G

AMPS, TACS

1983

-

2G

GSM, CDMA, EDGE, GPRS

1991

236 kbps

3G

UTMS, CDMA, HSDPA

2001

384 kbps

4G

LTE, WiMax

2009

< 1 Gbps


Throughout the years, mobile phone began garnering more and more connectivity options, apart from the phone connectivity itself. Some of these technologies are:
  • Infra-Red - significant reduction in phones equipped with this technology
  • FM-Radio
  • Bluetooth
  • GPS
  • WiFi

From the early days of WAP to the mainstream introduction of WiFi in our mobile phones, accessing the web on our phones has been long coming. In the WAP days, only specially designed pages could be accessed from our phones. Today, we can access the full-blown internet on our phones. The preferred practice though is to adapt our page for mobile access. Adapting for mobile access means that the page will fit snugly on the user's screen, eliminating side scrolling and zooming to read items. Providing sizeable buttons and click-able areas are also issues taken into consideration.



GeoLocation - where are you?

In conjunction with mobile phone development we explored the GeoLocation API. This API makes use of already known locations, such as cell phone towers and WiFi and uses them as reference points (triangulation) to determine your approximate location. After writing a bit of code, as shown below, to call the GeoLocation API, I tested it on a few browsers. Internet Explorer 9 failed to show anything. Firefox 4 took a good half a minute to get the location and was sometimes reporting errors. Opera and Google Chrome on the other hand, worked as they should.



Thursday, June 23, 2011

HTML5, CSS3 & JavaScript

Overview

HTML 5 is being touted as the future of web-development for some time now. The rise of HTML 5 has caused many battles with other web technologies. Most notable rival is Adobe and their Flash platform. Flash has been used in many web projects since it brings dynamic and aesthetically pleasing content to your web-page. This however came at a price of sluggish performance a notable lack of scalability. HTML 5 and it's related technologies are now bringing the same level of dynamic content by extending the already standard HTML. Browsers are still implementing HTML 5 and CSS 3 functions as we speak. The use of engines is being used by browsers as well to enable graphics to be rendered specifically through our GPU (Google Chrome and Safari's Webkit and Mozilla Firefox's Mozilla engine).

As we are seeing more and more of our mobile devices be HTML 5, CSS 3 capable (Mobile Safari on iOS and Chrome on Android) more companies are embracing the new technologies with some even jumping ship from Adobe Flash altogether. The outspoken Apple blatantly showed this is 2010 by issuing a demo reel of HTML 5 and leapt into a heated and humorous debate with Adobe for a few months. More sites are now popping up with developers gearing and getting more and more creative as the tools develop.



Giving It A Try

I took quite a tour of the new available features such as the great new functions of HTML 5 such as the web-storage. Saw some clever web-pages utilizing CSS 3 in a myriad of combinations to produce stunning yet surprising simple and clean results, both in the terms of the coding and in the terms of the user interface. Switching to advanced JavaScript, the demos found at Google Experiments are particularly good (check webpage: ro.me!) and some even quite useful.

Guided by these innovative solutions, I check some tutorials at w3Schools and implemented some of features, starting off with HTML 5 web-storage function. There are two ways of storing data on the client, either on the Local Storage or as a Session Storage. Using the sessionStorage function we can now create a simple output to show how many visits the user has made to the page in the current session. The code is shown below:

Photo & Video Sharing by SmugMug

A new attribute was given to the "input" tag; the email attribute. This checks matches the entered text with the basic email format of "x@x.x" and outputs an error message if it is not correct, as shown in the image below:

Photo & Video Sharing by SmugMug

Another well-requested feature, especially by web-designers is the ability to round your borders (this could previously be done by some well-placed images posing as your "border"). Now, in CSS3, by simply specifying your border-radius, you will get a rounded bordered box, shown in the code below:

Photo & Video Sharing by SmugMug

Animations will catch anyone's eye and as we can now start to deviate from Flash through the use of CSS3 2D & 3D Transformations and Animations. I experimented with a few of them and got to grips with rotation, translation, scaling and skewing transformations as well as defining keyFrames for the stages of an animation. The code is shown below:

Photo & Video Sharing by SmugMug

Photo & Video Sharing by SmugMug

I grouped my experimentation together into a single page that uses HTML5, CSS3 and JavaScript that will:
  • display the visit counter for this session and animate it to move left and right and back
  • show a form with rounded borders that will include an email and a password field
  • display a box with text, on which when the mouse is hovered, the box is spinned 360 degrees and changed in size, while having the text being resized accordingly


Concluding With The Same Old Cross-Browser Issues

Not all browsers support everything right now, and as I discovered while coding, you need to specifically call their respective toolkits for some of the code to work. The images below show the webpage in different browsers to highlight the differences between them.

Wednesday, June 15, 2011

Second Life: More Scripting

For this week, we're taking a thorougher look at scripting in Second life using Linden Scripting Language (LSL). First and foremost re-run through some basic rules and outlines of LSL:
  • it is a strongly typed language (every variable needs to be declared and they can only hold values of the relevant type)
  • variables: integer, float string, key, vector, rotation and list and some of their practical uses
  • basic loops and conditions (for, do, while) which are similar to Java and PHP
  • a look at some string functions
Through the basic understanding, we now applied some of the example scripts in-game and modified them to our preferences. These included a colour changing object, objects that open webpages and objects that change the light they emit when selected.

While scripting these objects we became more familiar with some LSL functions, such as, the different chat levels that are available in game (channels, owner chat, private messaging etc.), dialogue options, object listening and making use of vectors and lists.

Following up on this, I decided to implement an object that will give a passer-by the option to type a message which will be sent to the owner via email. First and foremost I create the object out of basic shapes and gave it some texture. The picture below illustrates the mailbox object.

Photo & Video Sharing by SmugMug

For the object scripting I made use of and combines some of the examples to produce the desired result. The script will check for the online status of the owner and always display that status as part of that object. When a user selects the mailbox, they are prompted with the option to enter a line of text in the chatbox. That line is then sent via email to the owner. The pictures below depict a user sending a message through the mailbox system.

Photo & Video Sharing by SmugMug

Photo & Video Sharing by SmugMug

Conclusion

This brings to an end the Second Life portion of this module. Second Life was quite an interesting subject to tackle. It is a niche in itself, a game that give you abilities and tools to create and manipulate objects at will. This "game" however seems to lack any purpose, there does not seem to be any quests or end-game objective or any form of completion. Thus, it is a platform on it's own. In today's world we are seeking integration in everything. You Log In with your Facebook or Twitter account to leave comments on blogs or forums, eliminating the Signing Up process and combining your digital life into a few accounts. As we discussed in class and as it was pointed out by several class-mates, if somehow, this platform could be integrated with social networking, then it could increase the appeal of the game.

Friday, June 10, 2011

Creating a complex object

Starting off I decided to create a room with a modern and free design. Following some tips and guides I commenced the object by creating a base for my building. It goes without saying that this object will be made up of more than one basic prim, so I had to first understand how to work with and link multiple prims.

Connecting prims requires that you first create more than one prim and then select them using the Shift key and change their properties to "Linked". Through this method, I built up the base and the walls. Through trial and error I came to realize that to align and place the objects together, one should make use of the positioning properties of the respective objects. This results in perfect alignment and not aligning them by eye and when you rotate the view, the object is totally not as it should be.

After I create the walls and the floors I wanted a roof to be made up in a cloud-like manner. This requires you to manipulate your object to deviate from the basic shapes. I created a basic object and manipulated and edited the options to create around 8 unique cloud-like random shapes and placed them around each other to form a cloud-like roof.

When I finished the basic structure I changed the textures of the objects to reflect wood, for the walls, some nice tiles for the floor and glass-like cealing. I also changed the texture of the entrance to reflect a grassy texture and added some benches and an orb-like transparent centrepiece.

I found building objects quite enjoyable though like most things, practise makes perfect so in order to learn how to translate what you have in mind onto a 3d model requires a fair amount of time.

Below is gallery showing the progress of constructing such an object

Thursday, June 2, 2011

Second Life - Creating Objects & Scripting

For this week's lecture, we first logged in appropriately on Second Life and added each other in-game. Following this, we were all instructed to meet up in a sandbox called "Fermi". A sandbox is a piece of in-game land were one is allowed to built their objects and can put them in their inventory for later use.

Meeting there, we all started to get to grips with building basic objects and the general controls as regards it's shape/size/rotation etc. I managed to create a wearable glowing halo by creating a torus shaped object, re-sizing it, rotation it, adding the glowing and transparency effects and finally wielding it.

Next, we started dabbling with scripting objects. This is done through the game's own scripting language called the Linden Scripting Language (LSL). LSL is runs on the server side and is loosely based on Java and C. It is made up of "states","events" and functions, and crucially, every script must have at least one state: the default state, and one event handler. "Events" and pre-defined and the user can define the respective handlers for these events when associated to a particular object.

In-game we created objects that say text when clicked or change their colours when switching states.

All-in-all again, the concept is quite neat but the delivery is hindered by massive issues of lag and glitches. Sometimes it took a fair minute for a particular script to run and up till now we are still dealing with fairly basic scripts.


Thursday, May 26, 2011

Introducing Second Life

What is Second Life?

Second Life is an online 3D game providing access to virual worlds. A player can create their own fully customisable avatar which is able to interact with the worlds. A player can also create their own objects using the in-built 3D modelling tool, which they may share with others.

Second Life's hierarchical system of objects is as follows:
  • Main Grid - The main area holding everything
  • Regions - residing in the Main Grid. A region pertains to a specific server and is made up of multiple prims
  • Prims - objects in-game are made up of prims (primitive types - geometrical shapes)
For these next few weeks, we'll be tasked to delve deeper into Second Life and understand and create our own objects as an end-goal.

The Basics

Downloading the client and creating an account was a breeze but upon logging in for the first time, the first immediate reaction was the amount of lag you experience. The objects were taking ages to load, so I headed over the the Preferences and reduced the quality to Low and increased the "Drawing Distance" slightly for the default Low value. Doing so resulted in good gameplay over better graphics and bandwidth usage.

The controls are very easy to understand, being quite similar to a typical 3rd person game. The addition of being able to fly always everywhere was also quite welcome. I started by changing my avatar's physical appearance.

After changing the appearance, I started to get more familiar with all the game's interfaces. How to handle objects, add friends, make landmarks, switch worlds and such.

Exploring

Being quite into planes and any type of vehicle myself, I decided to find out if I can drive one. After some searching and a few pointers from fellow players I learned that you can own a plane/vehicle by buying it for the Linden in-game money. The vehicles are advanced prims built by other players. When you buy one, you can keep it in your inventory and "use" it when you like. I also found that there are areas which let you test these vehicles, so I went to specific world as advised by another player.

The in-game objects that lets you create a temporary new plane, gives you an object which need to wear. This object is the controls for the plane and needs to be unequipped after each flight.

I also explored many world at random and found some pretty neat concepts such as: Central Dublin, multiple castles, paradise islands and even space/stellar worlds.

Photo & Video Sharing by SmugMug

Photo & Video Sharing by SmugMug

Conclusion

All in all, the game is quite enjoyable with a great concept but somewhat lacking in execution. The lag, unexpected crashes and multitude of buggy features tend to overshadow the game. In combating the latency issues I ran the game on both Windows 7 and the latest distribution of Ubuntu. On Windows 7, the game was quite stable but a bit laggy, while on Ubuntu, the viewer crashed every time I switched a world but on the other hand was less laggy (using same settings). I still have to get round to building objects, which I think will be even more interesting.



Thursday, May 12, 2011

Coursework 2 - File Manager

Introduction

Coursework 2 is a culmination of previous tasks, rolled into one. It takes what was previously learned in the PHP lectures and packs them in a task that aims at the integration of our PHP scripts in forming a suitable web-program.


Overview

Coursework 2, was as follows:

Write a remote Web space management system suitable for handling Web site content of various types. It should allow a user to add and organise files to a personal Web area which is secured by password. Again, there will be a connected theme, to be announced in lecture time.

This program should include the following features.

(1) Your program should be written as PHP scripts. The user should be able to work with this program via a Web browser from any computer connected to the Internet.

(2) When your program starts, it should ask the user to enter a password and username, and not allow the user to access their Web space unless they know the password. Passwords should be stored in an appropriate MySQL database.

(3) Once allowed access the user should be able to:

(a) Make and delete directories

(b) Delete files

(c) Upload new files

(d) Only be able to access their own space, which should have space limits imposed upon it.

User data and passwords should be stored in an appropriate MySQL database or file system which the PHP script can access; you must consider security implications. There are no restrictions on the style of the user interface, although you should consider ease of use and design to be issues too.

Beyond the basic file management capabilities you could also consider adding the following:

  • User preferences which alter the interface depending on who logs in.
  • Auto-update of files so when a Website has been updated locally all new files can be uploaded.
  • Support for mobile device (‘phone or PDA etc.)

Storing Files: File System vs. Database

When it comes to storing files I came across the old debate of whether to store your files on the server file system or directly in your database. I found good and valid arguments for either solution, which I have presented below:

File System Pros

Scenario for storing files on your file system and their location in a database

  • The ability to serve the files as static
  • No database coding is required to access the files
  • The files could be stored on a separate location to optimise performance
  • Reduce bottlenecks in your database
  • A database is at the end of the day, still on your file system
  • Easy caching

File System Cons

  • Files are easily in view in your file system
  • File have no real relations between them
  • Extra scripts need to be made to maintain integrity between the files and their locations on the database
  • Permissions to store files on your file system is needed
  • Easy association between the files and their owners/properties
  • Features like auto-sorting can be easily implemented
  • Data is stored in a single location, making it easier to backup or move to another server
  • No easy access to files through simply file system browsing
  • General notion is that the database is generally slower performance-wise
  • Lack of easy access to files
  • To backup your files, all the database needs to be copied

Database Pros

  • Easy association between the files and their owners/properties
  • Features like auto-sorting can be easily implemented
  • Data is stored in a single location, making it easier to backup or move to another server
  • No easy access to files through simply file system browsing
  • General notion is that the database is generally slower performance-wise
  • Lack of easy access to files
  • To backup your files, all the database needs to be copied

Database Cons

  • General notion is that the database is generally slower performance-wise
  • Lack of easy access to files
  • To backup your files, all the database needs to be copied

Decision

While looking into the matter, I also chanced upon a paper which researched and compared the idea that: files smaller than 256kb are faster to store in a Database and files larger than 1Mb are faster on a file system. The research analysed the performance with different file sizes and found the notion to be generally true, albeit less significant difference at the lower end. In general, large amounts of data to be transferred and stored, mostly above 1Mb are better stored in the file system, favouring performance.

For the purpose of the simple web-space I opted for a database solution and limiting the users’ maximum file size to 1Mb. Have a 1Mb limit is a fair assumption, since most documents and images are never larger than that. This will store my files in a central location and make them less susceptible to easy attacks, such as file system browsing. On the other hand, I am aware that they are now more subject to direct SQL attacks.

http://research.microsoft.com/pubs/64525/tr-2006-45.pdf

http://stackoverflow.com/questions/211895/storing-documents-as-blobs-in-a-database-any-disadvantages

http://imar.spaanjaars.com/414/storing-uploaded-files-in-a-database-or-in-the-file-system-with-aspnet-20

http://stackoverflow.com/questions/561447/store-pictures-as-files-or-in-the-database-for-a-web-app


Working Environment

A description of my working environment while developing this web-program

  • Developing on Windows 7 machine using Eclipse with PHP plug-in
  • Running Ubuntu 10.10 on a VMWare Virtual Machine
  • Xampp for Linux (lampp) installed on Ubuntu
  • Assigned a separate IP address for Ubuntu VM in my home network
  • Accessed pages from Windows 7 to simulate client accessing server (different IPs)
  • Testing browsers: Google Chrome 11, Mozilla Firefox 4, Microsoft Internet Explorer 9

MySQL Tables

The first stepping stone for this coursework was to create the tables needed in our servers’ MySQL database. I identified that two tables were required: a user table and a file table

User table

  • User ID
  • User Name
  • User Password
  • Creation Date

File table

  • File ID
  • File user name
  • Name of file
  • Type of file (MIME info)
  • Size of file
  • Content

These tables were created on the servers’ MySQL database


Register

The basic structure of the PHP code when a user attempts to register is shown below:

  • Check for any black fields
  • Check that both passwords given match
  • Connect to database
  • Check if the username is already in use
  • Add slashes to the password (reduce SQL injection attacks)
  • Encrypt password
  • Insert the data into the database
  • Return message to show completion
  • Redirect to Log In page

The PHP code is shown below:


Photo & Video Sharing by SmugMug

followed by a screenshot of the register form

Photo & Video Sharing by SmugMug


Log In

The code for the Log In page, is structured as so:

  • Check that the user has actually filled the form
  • Check if username exists
  • Connect to database
  • Get password for that username
  • Stripslashes of entered password
  • Encrypt entered password
  • Match encrypted passwords
  • Create Session if all successful and redirect to phpMainPage.php

The PHP code is shown below:

Photo & Video Sharing by SmugMug

followed by a screenshot of the Log In window

Photo & Video Sharing by SmugMug


Sessions

To prevent users from simply entering the URL of a PHP page and accessing it, a method for authenticating the user is required: hence PHP Sessions. A PHP session allows us to save information for later use on the server. Thus, it also enables information to pass from one PHP page to another.

For this task I intend to use the Session to:

  • Store the username and therefore by checking that it exists in each page, we can now verify if the user is indeed, a registered user, and is authenticated to visit that page or perform that action
  • Store notification messages, such as “Deleted file info.png”
  • Store the size percentage still available to the user

The PHP code that precedes every page to authenticate the user is shown below:

Photo & Video Sharing by SmugMug


Uploading Files

Before deciding on how to upload a file, some rules had to be made. It was decided that each user will have a space of 50mb each. Also, each file that is uploaded must not exceed 1Mb in size. When looking at the types of files to be allowed, I decided to allow:

  • .pdf – Adobe PDF
  • .doc, .docx – Old and new Word Document format
  • .xls, .xlsx – Old and new Excel Document format
  • .ppt, .pptx – Old and new Powerpoint Presentation format
  • .jpeg, .png, .gif – Image types

The proceedings of uploading a file are outlined below:

  • Check the remaining space available
  • Get the name, type (MIME) and size of the posted file
  • Check that the size of the file does not exceed 1Mb
  • Check that the type of file is of an acceptable format
  • Check the server for magic quotes
  • Addslashes
  1. Open file
  2. Read file
  3. Apply addslashes
  4. Close file
  • Connect to the database
  • Write query that will insert the name, type, size and content of the file into the database
  • Execute query
  • Close the sql connection
  • Notify the user

Actual PHP script for uploading a file:

Photo & Video Sharing by SmugMug

followed by a screenshot of a user uploading a file and receiving an appropriate confirmation message

Photo & Video Sharing by SmugMug


Deleting Files

Deleting a file is fairly similar to the other procedures:

  • Connect to database
  • Form the query according to the file chose for that particular user
  • Execute query
  • Close connection
  • Notify the user via the session
  • Redirect back to the main page

Script for deleting a file:

Photo & Video Sharing by SmugMug

followed by a visual confirmation of a user deleting a file, in this case, an image

Photo & Video Sharing by SmugMug


Downloading Files

When I got to the part of writing the script to download the file from the database, it proved to be quite problematic. The first part of the process was the same as the deletion of files, but I couldn’t quite get the “serving the file to the user” part quite right at first. After quite a bit of research and digging, with many false positives I found a working solution.

The process is similar to the deletion of files, with the exception that the file sent to the user through the use of “header("Content-Disposition: attachment; filename=$name");”. The size and type of the file are also passed to the header to instruct the browser on what to do with the passed file.

Script for downloading the file:

Photo & Video Sharing by SmugMug

followed by a screenshot of a downloaded file in Google Chrome

Photo & Video Sharing by SmugMug


Webspace Size Limit

The function for checking and limiting the amount of user uploads was stored in a separate PHP page. Giving the amount left in percentage seems like a good idea to further guide the user.

  • Connect to database
  • Write query to get the size of all the files of user given
  • Execute query
  • Put each row of size into an array
  • Add all the values of the array and calculate percentage from 50Mb
  • Add the result to the session

PHP script for the space remaining check:

Photo & Video Sharing by SmugMug


Main Page

The main page is intended to be the “central control panel” for the user, were they can upload/delete and download their files while getting the appropriate information such as notifications and current space remaining all at a glance. This undoubtedly is designed with user usability in mind.

The basic concept includes:

  • Displaying the name of the user logged in
  • Adding a Log Out button
  • A notification area (to display a message when a file is appended)
  • A button to select a file for upload, and one to upload it
  • A percentage metre of the space available
  • A list of all the files the user has, each having a download and a delete option

Getting the filename list was quite straight-forward; done with an SQL query and the list of files stored in an array. Being quite new to PHP, I encountered a problem with the idea of generating a table for each filename, adding a delete and download button, and having the buttons trigger the action.

Generating the table was not the issue and it was done by looping through the filenames and issuing html code for each filename. The problem came when I tried to trigger the PHP script by writing a redirection in the “onclick” property of the button. It seemed logical to do so, but in fact I was totally wrong, since PHP is a server-side script and you cannot simply call a page from within the HTML.

PHP typically functions by packaging your information into a form and sending it to the server. Building on this, I transformed my table for containing the filenames and buttons into a form. Having done so, I stumbled upon another hurdle. I was looping through the form generation and assigning a hidden value having name be an “echo” of the “filename[i]” from the loop. When the button is actually called, “i” actually contains the number for the last entry of the array. Therefore, effectively, the name of the last file was always being sent.

After a fair amount of reading I stumbled upon a similar issue posed by a fellow learner of PHP. The proposed solution was to actually add the “filename[i]” as an associative array in the name property. This was successful and I got rid of the hidden value and added a “Download[filename[i]” idea to the name property of each button.

When I attempt to now download and delete a file by clicking their respective buttons, the action and its’ filename are posted to phpEditFile.php were they are analysed and directed to the respective functions.

The PHP script for the Main page is shown below:

Photo & Video Sharing by SmugMug

followed by a screenshot giving an overview of the Main Page

Photo & Video Sharing by SmugMug


Future Improvements

  • Labels
  • Trash
  • Colour Scheme
  • Date Uploaded

Given the certain time constrains, and the task being an academic project, there were some functions that I wanted to add but couldn’t. First off an option to place a label for a file would have made the experience more Gmail-like and intuitive. Another feature I wanted to add was a hint of user customisation were the user can select a colour scheme for their Main Page, and the colour scheme being used every time the user logs in.

At the beginning I overlooked the need to save the date of when a file was uploaded. This would have allowed a sort by date option. Apart from these, with some more time and some JavaScript the web-program can become much more appeasing to the eye. It serves it function but somewhat lacks in eye-candy.

One more future improvement would be to eliminate the page refreshing. After some research I learned that in order to do this, one must make use of AJAX. It is now on the future, to-do list.


Conclusion and Reflection

Upon further consideration, the decision to store the files as in the database rather than directly to the file system might not have been such a great idea, weighing the respective advantages and disadvantages. For a simple, limited solution, the database option is a safe bet, but if you intend to scale out in a real environment, the file system option is much more suitable. If I had to start the task again, I would probably go for a file system approach. The database approach was an early decision in this task, which reciprocated throughout the whole task.

All in all, the task was a good learning exercise. Applying the various concepts picked up during the lectures and joining them together into one task, accompanied by independent research to resolve particular problems, was a good thing. A steep learning curve with any new concepts ensued, which undoubtedly took its’ toll at some times, but the end result was good.


References

W3Schools for PHP, CSS and HTML reference

StackOverflow Forums