File upload and validation class

File uploading, validation and security is such a pain for programmer. To simplify the problem I created a class called ‘File Upload and validation’. The class is currently hosted in phpclasses.org site and in Hotscript. For the people who are using or will be using the file this documentation will come in handy and useful to use the class efficiently.

File to Include:
You only need to include the main class file in your back-end server side form processing file. the main class file is ‘ MazUploadClass.php’.
Example Files:
Other two file, one is html file called ‘index.html’ and another back-end example PHP processing file namely ‘uploader.php’, in the package I included is to test out the class and and understand the way it works.
Functions:

uploadPDF($test,  $siz, $fletype);

This function is responsible for checking the uploaded file’s type and MIME type as well. This function will validate the uploaded file. The parameters all are mandatory. $test variable is the example variable of holding the uploaded file. Such as:

$test= $_FILES['pdf'];

$siz This variable is responsible for the uploaded file size, developer can give the file size limitation here so that the file exceeding the given file size won’t be uploaded and will show the error message instead.
$fletype is the variable for file type that developer want his user to upload. For example, if I want to allow user to upload image then my code will look like this:

$fletype= "image";

currently the class allows image, pdf, audio and video file type. The string $fletype variable should be holding exactly “image”(for Image), “pdf”(for pdf files), “audio”(for audio files) and “video”(for video files) those strings.

The function return an array of strings. The return value and error of files can be judged by calling this variable:

errorFlag['fileFlag'] == "yes"; /*if it is true than the uploaded file MIME type is not correct or file type is not valid Give user an error message. if false you are good to upload your files*/

Second Function:

createPath($fletype);//any string that you want to be named as a folder name.

This function will return a valid path created on the server while uploading the file. The path will be “user_uploads/$fletype/year/month/day/” from your root. only changeable variable is $fletype, other than that other string and variable are predefined and cannot be changed unless you hack the class itself.

Random Code:

randomCode();

This function ill create random code to add before the file name of uploaded file to make every filename unique.

Uploaded Function:

uploadToServer($tmpFileName, $originalPath);

This is the function to call to move the temporary uploaded file to the original path. If the file is uploaded properly then it will return true. $tmpFileName is the variable for temporary uploaded file and $originalPath is the path where the file will be stored, developer will be use this path to store in the database as a string.

Usages:
Using this class developer can allow users to upload image, pdf files, audio files and video files.
The class package file can be downloaded from Here.

Any feedback or bug report can be submitted in this blogs comment section. I will try to update as early as I can. If you want to buy me a coffee *that will be great* Donate.

Posted in Programming | Tagged , , , , | 5 Comments

Facebook Like, a simple wordpress plugin!

This plugin shows a facebook like button on your wordpress blog in your index page and posts. Just install the plugin, activate it from your admin and you are done. The facebook like button will show up in your main page with every post and in all individual posts page as well. This plugin is still on development, so any feedback would be highly appreciated.

Installation:
1. Download the zip file.
2. extract it
3. upload it to your blog’s plugin folder.The path should be wp-content/plugins/
4. Go to your blog Admin Page
5. activate the plugin ‘Facebook Like’

and you are done!

Posted in Programming | Tagged , , , | 11 Comments

Social Media, 140 characters of life!

Waking up in the morning to read the newspaper, listen to hourly radio or television news, nah the time is up for that. No more printed newspaper, no more TV and radio for news. No more going out to gossip with friends, no more socialising by going relatives home, no more seminar to learn about technology!

Social media, one kind of media to make people more social, no? well, in my opinion it is. Lets discuss and learn what we have right now and what we should know about them. What if you ask me to tell about myself I will give you my website address where you will find several social media sites link to know about me. Is it unsocial? I don’t think so, because there you will find more about me what probably, I can’t express to you face to face.

Twitter, Facebook, Ning, Tagged, Vkontakte, Hi5, and so on are some online social media sites that lets you connect with your mates, colleagues, friends, families, relatives and beloved. How much do we know about them?Do we use them? Should we use them? What are the benefits? A lots of questions will rise. In short, you should know some of them to keep pace with the technology, new culture and trend.

Twitter: A micro blogging site where you will be able to update your status, share some knowledge and links within 140 characters. 140 characters are enough to express the emotion or something isn’t it? well, for the limitation in twitter normally people use the shorter version of word spelling. Something that will get you helpful while using twitter:

  • Hashtag:hashtag ‘#’ is used before a wrod. It is being used to specify a group who have same interest with the hashtaged word. So some examples of hashtag words are #fail, #iesucks, #iwantthis and so on!
  • List:Its a module where a user can create a list and can include twitter-er whoever they want.
  • Mention:To mention somebody, anyone can use ‘@’ sign before their twitter user name.
  • Re-tweet:Now a days twitter added a new function where one can easily re-tweet others tweet by clicking retweet what appears under every tweet. Another way of re-tweeting is adding ‘RT’ and mentioning the user.
  • Direct Message:There is another option to message a user directly by going direct messaging page of twitter. Other way of Direct messaging is adding ‘DM’ and mention a user.
Posted in Blog, Websites | Tagged , | Leave a comment

Twenty Ten, celebration, Abroad Life and Me !

It was last year when I last updated my blog :P . It’s twenty ten(2010), a brand new year with lots of hope, inspiration for my walking in the clouds, a year where I need to finish some of my unfinished business, need to prepare for the happiest moment of my life, a year what will give me the chance to prove myself and a lots of other opportunities. I am also prepared for obstacles that I will have to face in this year.

It was a nice NYE I had passed here out of my country. I am thankful to Tan Jek Hui, one of my bosses, for inviting me at the NYE party with them. It was fun and interesting. I attended the wedding party of Ser Young(one of my colleagues) at 2nd January of twenty ten.  I am attending the university for this semester and applied for my visa. Those are all of important topics for last 1 and half months. Ohh I changed my house as well :D .

2009 was not that bad for me. I attended the university again, completed a semester, got a job in a promising digital agency, built my programming knowledge, worked with some geeks, created some websites, formed a group of promising young boys called polluxLab, started tweettering, become social media addict, gather some inspiration for my life, hell that’s  a lot. I have achieved so many things in the last year :)

There were something bad happened to me last year as well. However, it was not that scary. I have lost my laptops, need to pay a lots of  money to university. the most bad happened to me was I was physically broken, probably mentally as well in a specific point. I will try my best to be more perfect and will try to avoid any mistake in this year.

Wishlist for this year:

  1. Become a ZCE
  2. Become pro in Java
  3. Research and Development some ideas
  4. Regular Blogger
  5. Be with my Beloved
  6. Solve some personal problems
  7. Find the way of becoming happy! :)

Happy New year :)

Posted in Personal | Tagged , , | Leave a comment

MySQL search query, collation and case sensitivity.

I was working on mysql database and was creating a search system module for a big mysql database. Everything was going fine as usual, query was working, no bugs, database was responding. However, the main problem that I notice was case sensitivity search. My searching query was case sensitive. Although I used LIKE ‘serachquery%’ in my code but the case sensitive search cannot be prevented. If you are having this problems then there are some solutions.

The first thing is you need to know about the database collation. What is collation? shortly ‘A collation is a set of rules for comparing characters in a character set’. If you want to know briefly about collation then you should look at mysql documentation about collation, encoding and character set.

There are three type of case sensitiveness in mysql database collation.

  • ‘_bi’ -> This means binary case sensitive
  • ‘_cs’-> This means case sensitive
  • ‘_ci’ -> This means case insensitive

Solutions:

1. First, look at your database and see what type of collation did you assigned for your table entity?? If it is binary case sensitive AKA ‘_bin’ or case sensitive AKA ‘_cs’ then your normal LIKE ‘searchquery%’ won’t work. So the first way is if it possible to change the collation type.

2. The second way is much easier and code related. the code can be something like this.

SELECT tableEntity FROM table_name WHERE UPPER(tableEntity) LIKE UPPER('search_query%');

The logic for this query is whatever search query is, we are making the query in upper case using UPPER() function of mysql and we are making the result of our tableEntity in uppercase as well.

Hope those solutions will help you. Happy coding! :)

Posted in Programming | Tagged , , , , , | 3 Comments

"Supercalifragilisticexpialidocious"~~It is a word

One of my friend was wondering to get this word “Supercalifragilisticexpialidocious”. Actually that time same went to my mind what is the definition or behind thoughts of this word? After a long web search I came up with this.

Supercalifragilisticexpialidocious is an English word in the song with the same title in the musical film Mary Poppins. The song was written by the Sherman Brothers, and sung by Julie Andrews and Dick van Dyke.
Since Mary Poppins was a period piece set in 1910, period sounding songs were wanted. Supercalifragilisticexpialidocious sounds like popular folk songs “Boiled Beef and Carrots” and “Any Old Iron”.

Origin
Supercalifragilisticexpialidocious is a nonsense word. The critics’ belief that the word itself has obscure origins has created some debate about when it was first used historically. According to Richard M. Sherman, co-writer of the song with his brother, Robert, the word was created by them in two weeks, mostly out of double-talk.
Roots of the word have been defined as follows: super- “above”, cali- “beauty”, fragilistic- “delicate”, expiali- “to atone”, and docious- “educable”, with the sum of these parts signifying roughly “Atoning for educability through delicate beauty.” This explication of its connotations suits the nature of Mary Poppins, who presents herself as both extremely beautiful and also supremely intelligent and capable of great achievements. However, it should be noted that although the word contains recognizable English morphemes, it does not follow the rules of English morphology as a whole. The morpheme -istic is a suffix in English, whereas the morpheme ex- is typically a prefix; so following normal English morphological rules, it would represent two words: supercalifragilistic and expialidocious . As one word, it also violates the rule that the letter c cannot sound like a k when followed by an e , an i or a y .

Additionally, according to the 1964 Walt Disney film, it’s defined as “what you say when you don’t know what to say”.

In the 1942 movie “The Undying Monster” (directed by John Brahm), the character Rob Curtis (played by James Ellison) says of character Christy, “She has an overactive supercalifragilis.” He goes on to define the word as “female intuition.” This passage does not appear in the 1936 novel by Jessie Douglas Kerruish.” The screenplay was written by: Lillie Hayward and Michael Jacoby.

Info from–>Wikipedia
You will get more info here

Posted in Programming | Leave a comment

File upload issue [part 2]

I have already discussed about the file upload issue in this post. In this blog post I will give some code for uploading the files into the server.
Easy way to check the file extension in php:

<?php
$ext = end(explode(".",strtolower($_FILES['theupload']['name'])));
?>

In this line of code I get the extension of any uploaded file in our script. after getting the extension you can check whether it is an image or a video. In this portion I will check whether it is an image or not by a normal conditional statement.

<?php
if($ext=="jpg" || $ext=="jpeg" || $ext=="gif" || $ext=="png") {
//do stuff
}else{
 //give user an error msg.
}
?>

Problem while uploading long tail video?
It is a problem while uploading long tail video on the server even when you want to upload a video file more than 16 MB without configuring your php.ini file, you will have problems :( , problems that can make you crazy over your php script. Frankly I was that much crazy with my php script. I knew that I do not have problems in my script but while uploading long tail video the whole screen become blank :( . There is one thing you can do in this situation. You can search into google about uploading long tail video and another important thing is checking your php.ini file for the uploading configuration. Here I am listing the settings in php.ini what we need to modify.

file_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time
post_max_size

Read the documentation there in the file and after changing the settings you need to restart your xampp. You are ready to upload now according to your limit settings :)

Posted in Programming | Tagged , , , , , | Leave a comment

Google visualization API and Geomap

Most of us who use internet already know about Google Map and its API, some of us also know about visualization API as well. In short actually in the way how Google itself describe visualization API is “The Google Visualization API lets you access multiple sources of structured data that you can display, choosing from a large selection of visualizations. Google Visualization API enables you to expose your own data, stored on any data-store that is connected to the web, as a Visualization compliant datasource. Thus you can create reports and dashboards as well as analyze and display your data through the wealth of available visualization applications.
Google has more description and documentation on this API. Geomap is one of the functionality that is performed through using Google’s visualization API. Geomap is rendered on a embedded flash player in the browser. Geomap is a map of country, continent or region map where we can use colors for specific region. Values are displayed as a color scale, and you can specify optional hovertext for regions. I will be describing some of the functionality of geomap. what we can configure and modify and how to use it in our websites.

Loading:
Load package of google is “geomap”
so the code for loading is:

google.load('visualization', '1', {'packages': ['geomap']});

The geomap visualization class name is

'Google.visualization.GeoMap'

These codes are permanent and must have codes so you cannot modify that to call geomap and visualization API.
the last we have to include some file in order to load the google visualiztion API library and I am assuming that you already have your personal API key. We have include those file in the beginning of the HTML best if you add them in head section of html page.
required only for markers, and only when not specifying lat/long values

<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;key=ABCDEFG"></script>

The main library including file

<script type="text/javascript" src="http://www.google.com/jsapi"></script>

Setting the onload the callback function by stating those scripts right after loading the geomap.

google.setOnLoadCallback(drawMap);

The main thing here is

drawMap

. This is our main function where we will declare the main functionality of Geomap. You can change the function name if you want.
Strating of main function
In the beginning of creating the function we need to declare the class name code will be

var data = new google.visualization.DataTable();

after that we can declare the rows and columns for drawing map and setting the value as well. We can have as many as rows we want. To declare the numbers of row we use this code

data.addRows(1);

We took data as a variable where we declare a new class and we declared we will have ’1′ row inside the

addRows()

function.

Now we will declare two column. one is for adding the title of a small popup type box what will be shown after hovering the mouse on the markers in the map. To add the first column we can add this line

data.addColumns(‘string’,'city’)

Here we pass two parameters inside addColumns()one is declaration of data type what is string and another one is hovertext. The same will go for the other column where we will indicate number as the data type and value.
the whole part of adding rows and columns will look like this piece of code.

function drawMap() {
var data = new google.visualization.DataTable();
data.addRows(1);
data.addColumn('string', 'City');
data.addColumn('number', 'No');

Now we can use setValue() function to set up the value for columns. This code is one example of setting value in the columns where it will take three parameters whereas one is row index, column index and value respectively. We have to specify two setValue() function since we used two columns. That means for every column we have to set value.
We will use those portion of codes.

data.setValue(0, 0, ‘Welington’);
data.setValue(0, 1, 12);

Now we will be using ‘NZ’ as region option. We can modify the region by changing it as country code name e.g:IN->India, BD->Bangladesh etc. We will use markers as ‘dataMode’ and we can also cofigure the width and height of the map by changing the value of width and height in pixels. We can use colors also by modifying the colors options. We can use zoom level as well. The code will be look like until now :

var options = {};
options['region'] = 'NZ';
options['width'] = '400px';
options['height'] = '400px';
options['dataMode'] = 'markers';&lt;p&gt;&amp;nbsp;&lt;/p&gt;

var container = document.getElementById('map_canvas');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);

Last three lines of this portion of code are the final lines where the first variable detect the id of div in html page whereas geomap declare the main class and last line is used to draw the map.

Something that you can’t do using geomap

  • You can’t drag the map
  • You cannot scroll

Advance documentation and live examples are here
Hope this post can help with your simple questions about geomap. Comments is highly appreciative.

Posted in Google API, Programming, Websites | Tagged , , , | 7 Comments

Debugging, Quick Development of CSS using Firebug

When I learned CSS it was extremely tough for me to adjust the exact CSS style for a web page to work with JavaScript and XHTML. Although I am not a designer, I am very much interested about CSS for its simple and easy coding style as well as main design language for a web page. I remember the days when I didn’t know how to modify or examine the CSS codes on the fly. Every time i got bug related to CSS I had to change code of style-sheet and then upload into ftp and then try again…whew..the boring work to be done. Then I learned how to catch and fix the CSS bug on the fly using firbug. When you run a script in the browser then you can’t say what exactly the problem is whether it is problem with padding or something else. Or you may try the different ‘img src’ to try whether it is fit for the page or not. Those thing can be tested without changing the codes in the style-sheet but changing the codes in the browser itself. sound funny?? Let me explain how?

Most of us, who are programmers, know about firebug. Who doesn’t know, Firebug is a development tool for firefox which is also called add-on of firefox what will help to modify CSS, XHTML, JavaScript live on the browser(firefox).
Tools you need

  • Firebug installed in the browser(firefox)
  • any page consist of xhtml and designed with CSS open in the browser

Firebug icon in the browser:
After installing the firebug you can see there is one icon look like firebug in the bottom right corner of your browser. To open and close the firebug you can click that button. Here is the screen shot.

button

Inspecting the CSS in firebug:
Here comes the interesting part of the CSS development. After clicking in the firebug button a new small window will comes up at the bottom of the browser. Just like the screen shot.
firebug screen
Left upper corner of the firebug screen there are three button. First one is all about firebug which is a firebug button. Second one is inspecting button with a small cursor. If you click that button and mouse over anything in the page then the whole xhtml or html structure will e displayed in the mini window of firebug which is just after the firebug window navigation bar. Assume you want see the CSS of any website’s or your web page’s heading pictures and CSS for your header.html which you include in the main file and visible when you open the index.html file. Just open the file you want to look up through firebug and open the firebug by clicking firbug button and then click the inspect button. Mouse over in the main browser page what you want to inspect. click to stick with that specific div or table to look after the structure carefully and to change it in the firebug window. Now come and look at the firebug window. You can see the xhtml structure in the left and CSS in the right, What you mouse over and clicked in the main browser page. here are some screen shots to make it clear.
mouseover
HTML Part:

html part
CSS Part:
css part

Posted in Programming | Tagged , , | Leave a comment

Some unimportant thoughts of mine

Walking alone on the road. Thinking of something strange. I am like that what I do, what I think there is no explanation even I don’t know why I do those things. Strange! Isn’t it?? Still now I am writing without any plan, thoughts, explanation. By the way, I am warning you after read all those crap in this post your head will be jammed and you don’t dare to blame me because I didn’t compel you to read this post ;) Last day I was thinking about human minds and their target or goal of life. What I found was interesting. Everybody has their own goal including me! That was pretty disturbing when I found I also have a goal to reach and accomplish some task actually some important task of my life :( However, my goal and task are different from others. I have a goal of getting someone whereas other people have goal to be successful in life. don’t get me wrong here, it’s true. If you ask yourself, what I want to do in the future? or In which position do I want to see myself at the age of 35 or 40? I am sure you will get an answer and it will be something like “a successful man…good position in a society…having my own car and house a beautiful wife as well ;) “…But for me the result comes pretty differently when I ask myself such kind of questions.

What are those?? Something that can prove easily that I am mad. I think I will be with my beloved. Doesn’t matter how rich or poor I will be. I just want to be with her. If anybody will ask me about my goal then I will answer without any doubt that my goal is to get her!!

Posted in Personal | Leave a comment