About The Photo Album


Additional Features   |  Future Features


History

The Photo Album was created for my Web Programming class that I took as a junior (Spring 2003) at Baldwin-Wallace college. This project was suppose to help us become more familar with CGI scripting using Perl as the main script language, introduce us to .htaccess and .htpasswd files which in short, prompt users with a login screen before they can enter any pages, as well as using the ENCTYPE="multipart/form-data" for the form field which allows the user to browse their computer for a file (used for the Upload feature). Listed below are the main requirements to successfully complete the project.

Features
  • Allow user authentication through .htaccess and .htpasswd files (protects all of the files in folder that reside with these two files and also all files in the remaining subfolders)
  • If the user logs in as 'guest' their only functionality will be to view the files in the photo album, otherwise the 'maint' account gives the user full access to the Photo Album
  • If the user logs in as 'maint' they will be allowed to view all files, as well as have access to delete/add users to the photo album, and to be able to delete/upload new pictures.
Files
Main Title Page
Where users can ONLY view the files
Maintenance person can choose to mangae users or manage files
Page where 'maint' can add/delete users
Used to add a user to the .htpasswd file
Checks if 'user' or 'pass' was left blank
Page where 'maint' can delete/upload new files to the photo album
Script to upload the specified file to the server
             Note: Some of the pictures referenced for each file have more features on them than what I stated due to the fact that I written this page after I had              already wrote some of the new features.

One of the major reasons for this project was to have a way of adding files to the server at BW without being directly at one of the lab computers on the campus or FTP-ing to the site. Instead, all I would need to do to add files would be having a connection to the internet. After completing this project, I did recieve a 100% on it since all the functionalities/features worked as they were supposed to. Overall, I believe this project took me about 2 weeks to complete even though I was alotted 3 weeks to complete it.


Additional Features

After completing the Photo Album Project, I decided that a few more features would make it even better than what it was supoosed to be. So during the summer of 2003, I started working on these new features - I had a huge list of them and eventually I came to the conclusion that this would be an ongoing project throughout the summer as well as the school year. However, I didn't mind because I knew that it would help me with programming in Perl, learning new functions in Perl, and also I would have something at the end that would be very useful - a webified file album that I could access/update/change whenever and wherever I was connected to the internet.   Below are the features that I currently have completed since I have been working on it in during the summer along with a description of how I went about completeing each feature.


File Size
I wanted the album to display each file's file size - that way I would know which file was taking up the most space at a quick glance. I did some searching and reading on the internet and found that Perl has a function called 'stat' which gives staticts on a file. Just for reference, here are all the statistics that the stat file gives -

stat($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks)

As you can see, $size is the 7th slot in the array so I just created a variable and stored the 7th value of stat into that variable. It turns out that the size of the file is in bytes so I had to do some math to that variable to get it to display either KB or MB depending on the size of the file. I also created a variable that kept track of the total size of the directory - this is helpful since I can visually see from the webpage how big my 'pics' folder is without having to FTP to the BW site and then choosing properties on the folder.

Different File Types
The more I used the photo album, the more I realized I was uploading files that weren't neccessarily photos/pictures. Many times, I wanted my friends to see a video or listen to a song so I would upload it on the server and then send them the link to it. However, if I was at 'view.cgi' or 'filemaint.cgi' looking at the files in the folder, a preview of the non-picture file(s) wouldn't show up. So I decided that I would display some sort of icon for video, music and whatever other files I uploaded. After having the icons sized and ready to be displayed, I had to come up with a way of parsing the file extension from the file and then from that file extension I would display the correct icon. While writing the upload function, I remembered I used a function that reversed the file name and then read it. Therefore, I used the same method - reverse the file, read the first four characters of the reversed file name, and then if the first three were say '3pm', the file is an mp3 and I would display a music icon. I ended up adding another checkpoint for the .mpeg file extension since that it a 4 string extension. The check that I performed was if the fourth character wasn't a '.' I re-read the reverse string and read 5 characters this time. As of right now, I have the ability to display video, music, and flash icons for those file types. Eventually, I will have a large list of different file extensions for many different file types and different icons will be displayed accordingly.

Renaming Files
Another useful feature that I thought would add more functionality to the photo album is a renaming feature. With this, I would choose a file to rename, and then the file name (not the extension but just the name) would be displayed in a text box where I could edit the file name. Underneath the text box, there are two buttons - one to submit the new data and change the file name and another one to cancel the process of renaming the file. In order to accomplish all of this, I first needed a nice looking icon that the user would click on to rename the file. I searched for an 'abc' icon since the letters represent renaming in a way, however I couldn't find any that I like so I ended up creating one in Adobe Photoshop. Next I need a way of displaying the text box and the buttons after the user clicked on the 'abc' icon. To do that, I made the link of the 'abc' icon pass along a paramter - the filename. So next time the page was reloaded, if the param() function has the file name in, then instead of displaying the regular info. about the file, I would display the text box and buttons. Once again, in order to NOT display the extension of the file, I had to parse the file in reverse until I read a '.' - then I stored the renaming characters in a new variable and then re-reversed the reversed string to display the filename. This may sound confusing but if you just think about for a second, it will make sense. Ok that covers how to display everything properly in order to start the renaming process - now how I renamed the file. I ended up creating three variables, one that gets the original file name (I passed that along by a hidden field in the form, just gave the hidden type the name of my file) and one that gets the extension of the file because I split all that up so the user couldn't change the extension. My third variable grabs the parameter passed from the text box - the new file name. After I created those variables and made them get the proper fields from the parameter passing, I did a simple check to see if the oldfilename variable is equal to the filename that was just used to process all the information pertaining to that file in the loop. If both match, I know I can rename it. The first thing I had to do was join the newfilename and the extension - that was accomplished by the 'join' function. The 'join' function took the newfilename and combined it with the extension - basically the join function is the exact opposite of the 'spilt' function.

$newfilename = join '', $newfilename, $extension;

Now that I joined those two variables together - I had a vaild filename. Next, I had to do some error checking to see if the newfilename contained any whitespace characters. If I didn't do this, whenever I wanted to see the picture, the webserver would state that the address doesn't exsist because whitespace characters don't get along with the webserver. So I used the search feature in Perl to go through each character in the newfilename and see if finds a whitespace character. If it did, I had it replace the whitespace character with an underscore. The exact code for this is...

$newfilename =~ s/\s+/_/g;

where =~ specifies the bitwise operator, s/ is the search field, s+ is multiple whitespace character (s would just mean one whitespace character), and /_/ replaces the whitespace character with and underscore. Not sure what g means but I'm guessing it means go to the next character. Ok, now that the filename is suitable for the web, I have to replace the oldfilename with the new one. Lucky for me Perl has a 'rename' function built in where you give it the oldfilename and then the newfilename and it replaces them.

rename($oldfilename,$newfilename);

Well that's how I did the rename function, if you have any questions, feel free to e-mail - a link to e-mail is at the bottom.

Uploading Multiple Files At Once
Well, this was actually easier than I thought. Maybe it was because I thought about how I would do it for a few days before I actually started writing and experimenting with the code. Anyways, all I had to do was give each of the fields where one can upload a file a unique name. The name that I had already when uploading one file was 'fname' which stood for filename. I therefore just added a number at the end of it - 'fname1' - and then did the same for the others. Since I had six uplaod fields, I had 'fname1' thru 'fname6' respectively. Now that I had that set up, the next thing to modify was the upload.cgi file to make it so it go all six parameters that were passed when submitting the form. Since I used numbers, it was easy to grab each parameter by using a counter. I initialized a variable 'i' to equal 1 at the very beginning. After initialization of that variable, I created a while loop that would loop through until 'i' was less than seven. Ok, now the loop is setup, the next thing I have to do is grab the filenames from each of the upload fields. Right now, the way this is accomplished is by simple if statements that check to see what 'i' equals. If it is equal to 1 say, then I give $fpath (filepath) the path of the first filename.

if($i==1){ $fpath = param('fname1'); }

I do the same with the others when 'i' equals there number. After that, $fpath just uses the same code I had to upload one file and uploads its file - then goes onto the next. The only check I had to do was if $fpath was blank.

while($fpath ne'')

Mainly, that line checks to see if the variable $fpath is blank meaning I didn't have a file to upload in that field. All the code to write the file on the server is inside that while loop. That is about it besides I had to write some extra code to display what files were uploaded successfully. I created an array called @fnames inside the loop that increments 'i' and everytime it went through the while loop, I stored the filename in a slot of @fnames such as

$fnames[$i] = $fname;

That way, I had a way of displaying the filenames that were upload successfully. So that is how I completed that feature on uploading multiple files at once. I'm still gonna work on the code a little because I think it is a little redunant, I believe I can shorten it up a bit. Also, right now six messages popup about files being uploaded successfully even though I may have only uploaded one file - so I have to work on that. But I got the overall theme completed.

User Has Access To Upload Files
Coming soon...


Future/Upcoming Features

As I've stated before, while adding new features to the photo album, I've thought of more that could make the photo album even better. That said, this photo album will be constantly updated and changed as this is an ongoing project due to the fact that I keep coming up with new ideas. Here is a list of what I would like to add or want to add to the photo album. I won't go into any descriptions about these, but rather just list them. Once they have been completed, they will be added to the 'Additional Features' section and have a written description about what I wanted and how I accomplished it.
  • The ADMIN of the site - me - would have an option in the add new users sections where I can make other admin's. However, I wouldn't give full access, only access to upload new files (NOT deleting or renaming) as well as NOT being able to add/delete new users. Basically, just access so they can upload their files to have access to on the web.  Completed (7/31/03)
  • A way of displaying only certain file types - say display only video files
  • A way of displaying all files but sorted by file type. So all pictures would be in one section, all video, music, etc. in another.
  • Displaying how many times each user has accessed the photo ablum
  • Having new users enter information in a form asking for access to the site, and then an e-mail would be sent with a random generated ID that they would have enter to stop from spamming
  • Moving files around on the server by adding new folders. Would have a select files to move and the destination on the server - then it would move those files.
  • Having a way to allow users to change their password.
  • Making a way of updating the site by editing the files online. It would resemble the way the source.cgi file looks like, however there would be a submit new changes button and a cancel button at the bottom.
  • Adding a feature that would make it possible for me to hide certain files in my photo album from other users. That way, if I had something important in the photo album, only I would be able to view that file and no one else could.
Well that is just a temporary list of what I want to add to the photo album. I'm sure more options will pop up in my head and I'll try to jot them down here - just to keep a running tally. If you would like to e-mail me about the photo ablum - either questions/comments/or features that should be available - Click Here To E-Mail Me.  I'll try to respond to the e-mail about what I think, but either way, thanks for e-mailing me. This whole project took a long time to make fully functional as it is as well as the design and colors used even though those are only a small piece of the page. In any even, I appreciate your time to read all that I have done - Steve.



Title Page    |   View The Pictures In The Photo Album