Wednesday, December 3, 2008

Converting Excel date/time to Unix timestamp






I was working on excel sheet reports other day, and i came across an inetersting problem. I was using Excel reader class to read the excel file, which wa containing one column of date. While reading that column value, I found that, it contains some numeric value which was not unix timestamp value. I was puzzeled for some time.


After some searching and surfing on netty with the help of developer's biggest help Mr . Google, I came to know that Windows and Unix system behave diferrently to store the time stamp. I found the same question was asked in one of google groups, so finally i got the reason to put this on my blog.


In Unix system timestamp is stored as integer in terms of seconds. If we consider the current timestamp value in Unix, it is the no. of seconds passed from 1 January 1970 00.00Hrs till now. One important thing is, Unix timestamp is measured with reference to GMT time. That means there is no time-zone adjustment considered in case of Unix timestamp.


In case of Windows time it is stored as floating point/real number but in terms of days. For current timestamp, the no. days spent from 1 January 1900 stored in integer part and fraction of the day stored in the fractional part of the timestamp.


Once this was cleared to me, it was rather easy to go further.

Here are the conversion calculations



$intDayDifference = 25569; //Day difference between 1 January 1900 to 1 January 1970

$intDay2Seconds = 86400; // no. of seconds in a day

$intExcelTime //integer value stored in the Excel column

$intUnixTime = ($intExcelTime - $intDayDifference)*$intDay2Seconds;



Even after doing all this, you may find the calculations are not absolutely accurate, and that is because fractional part of the Excel time. The reason behind doing so is that all I need to do is to convert a date from Windows format to Unix format. So fraction part of windows time won’t affect a lot for my requirement. But if you use this calculation for converting a date-time from Windows format to Unix format then conversion of the fractional part should done.


I hope this would help you to convert timestamp between unix and windows. If you have any comments or questions feel free to ask. You can even contact me at ninad.blog@gmail.com

Thanks.



Monday, December 1, 2008

Setting innerHTML gives error in IE





innerHTML ::


The innerHTML property reflects the content contained by the referenced element, including all the HTML elements.

For example, consider the following <DIV> element:


<DIV ID="Address1">

Shiv Prasad,<BR>

1, Rajendra Babu Road,<BR>

Wadala,<BR>

Mumbai, India

</DIV>


The address' innerHTML property (obtained by referencing it via its ID property) would be:
Shiv Prasad,<BR>
1, Rajendra Babu Road,<BR>
Wadala,<BR>
Mumbai, India .



The innerHTML property has read-write permissions, meaning that HTML content can be 'written' into any element through scripting, with the document being re-displayed accordingly, dynamically re-positioning surrounding document content. The new HTML content would adopt whatever stylings (and ID) were applied to the referenced element, before the new content was supplied.


However innerHTML property works for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR. I checked with couple of browsers, and found IE is the most problematic. IE gives error and halts the execution of javascript if you try to set innerHTML property for above said elements. Works fine with mozilla firefox & safari though. This is one more reason why Microsoft should look for the products with better quality.



Monday, October 27, 2008

Server side video conversion (video conversion to flv or any other formats)

My blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
http://www.web20world.com/server-side-video-conversion/
and update your bookmarks.

Video Handling / embedding in web site





Hi guys,
Its been a while, i have written an article, but i am back now.Now a days most of the sites provide video tutorials / video uploading - playing facility. I have been working on video based network site since last one and hhalf year.
This session is all about handling videos on server side. I hope you would find this helpful, for basic information about video encoders / handlers.

We will split our tutorial in two part.

1) Play video in original format
2) convert video to flv (or other format) on servr side to play in custom player.
In this part we will discuss only about embedding video in web page.

#1
Embedding windows media player would be the simplest solution for this.


Here is sample code

<OBJECT id="VIDEO" width="320" height="240"
style="position:absolute; left:0;top:0;"
CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<PARAM NAME="URL" VALUE="your file or url">
<PARAM NAME="SendPlayStateChangeEvents" VALUE="True">
<PARAM NAME="AutoStart" VALUE="True">
<PARAM name="uiMode" value="none">
<PARAM name="PlayCount" value="9999">
</OBJECT>

You can control behaviour using parameters provided by windows media player i.e. obj.Settings.autoStart,obj.Settings.baseURL,obj.fullScreen etc.


#2. Second way is to after converting video in fllv, we can shopw that in flv player.
Many of the times i have been asked whether we can get free flash player who can play flv file.
I use our cusomized player which we have bult up our own (most of the video sites do).
But if you want to use some free flash players,
Here is one i have attached which i downloaded from http://www.jeroenwijering.com/?item=JW_FLV_Player
Here are some more links


1) http://www.jeroenwijering.com/?item=JW_FLV_Player
2) http://www.videospark.com/index.php?ssp=24
3) http://www.any-flv-player.com/flv_player/put_a_flv_player_on_your_website.html
4) http://www.pixel2life.com/publish/tutorials/514/independent_flv_player/


Thats it. You can embed video.
If you want to see how to convert video inflv on server, please read second part of doc.

If you have qny question or doubt feel free to contact me at ninad.blog@gmail.com

Friday, August 22, 2008

Upload Bigger files

Guys, As we have discussed, file upload in php is quite easier,
If you are newer to php file upload please refer to
(http://softwareguy82.blogspot.com/2008/08/simple-file-upload-in-php.html).

In this article we will discuss how to upload files with bigger size (200 mb / 300 mb or even more).

1) One approach is to mention MAX_FILE SIZE in the form itself.
<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name=" file" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>


By this approach, you can limit file size.

2) php.ini change
Php has global settings in php.ini for max file size.
Here only change in max_file_size is not sufficient. Some other corresponding settings are also needed.

Change following values
upload_max_filesize = 200M
post_max_size = 250M
max_execution_time = 900 (or -1 will also do, but be careful, this will allow hackers to attack on your server)
max_input_time = -1
memory_limit = 250M

That’s it. This setting should allow to upload files with bigger filesize.

3) On shared server, its not possible to customize php.ini. This is biggest hurdle.
And ini_set() doesn’t work for above said variables.
One common practice is to use .htaccess provided you are working with apache server.

In htaccess file paste following lines
php_value upload_max_filesize 200M
php_value post_max_size 250M
php_value max_execution_time 900
php_value max_input_time -1
php_value memory_limit 250M

If you are still facing problem while uploading; check apache config setting (httpd.conf) “AllowOverride” for directory level. That’s should be ALL.

That’s it guys, This should wrk.
Send me your feedback on ninad.blog@gmail.com


Domey Bank Landing Page

Hey Guys

I was checking my gmail today morning and guess what i saw in my inbox.

i got this email saying Axis banking online account has been violated.
Now joke is, i had an axis account 1& half year ago. and it has been closed couple of months ago :)).

Then i just visited the link provided by those guys in the email and to my surprise it was a phishing website

Check out the content of the mail below:-

Security Alert:

Attention! Your Axis Online Banking Account has been violated!

Someone with IP Address 81.102.72.19 tried to access your personal account!

In accordance with Axis Online Banking User Agreement and to ensure that
your account has not been compromised, access to your account was limited.

Your account access will remain limited until this issue has been resolved.

Please follow the link below to resolve this problem:
https://www.axisbank.com/security/resolve=acct

Thank You.

Accounts Management As outlined in our User Agreement, Axis ® Bank will
periodically send you information about site changes and enhancements.

Visit our Privacy Policy and User Agreement if you have any questions.



Now if you look very carefully to the link, you will notice that the actual axis bank one but the href given is
http://e-nocleg.com/baners/index.php?bank=www.axisbank.com/BankAway/dJSESSION2973743u383h3bjhffufDHJUGHSbwayparam=dabCcRhcJfLjtYCXCZuARrnhMYei0G7D&type=personal&stge=2&id=fyjdL1LXSFkUnut
which is the domey link

Here are the screenshots of actual axis bank & domey Phishing page.

Original Axis Bank Page














Domey Phishing Page















Please keep in mind, all the banks use Secure Socket Layer or HTTPS to perform banking operations, so never never perform transactions when url does not contain https://

Pass this message to your frenz, to be careful with such frauds.

Thanks.

Tuesday, August 19, 2008

Simple file upload in PHP

File Upload In Php

One of the important aspects in php is file upload. File upload in php is very simple, but you need to be careful while doing it, because allowing users to upload file to server means possibly providing whole can of worms.

To upload file create one simple html form .
<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Choose a file to upload: <input name=" file" type="file" />
<input type="submit" value="Upload" />
</form>
</body>
</html>

Note the attributes of the form here.
enctype = "multipart/form-data". It specifies which content-type to use when submitting information back to server. Without these requirements, your file upload will not work.
Action = php script path, which will have php code to upload the file to desired path
Method = “POST”

Here, another thing to notice is the hidden form field named MAX_FILE_SIZE. Some web browsers actually pick up on this field and will not allow the user to upload a file bigger than this number (in bytes).
You can also set this value in php.ini. Also make sure that file_uploads inside your php.ini file is set to On.

Now it’s time to create upload.php; which has been referenced in form tag.


//Сheck if file is present
if((!empty($_FILES[“file”])) && ($_FILES[“file”][“error”] == 0)) {
//Check if the file is JPEG image and it”s size is less than 350Kb
$filename = basename($_FILES[“file”][“name”]);
$ext = strtolower(substr($filename, strrpos($filename, “.”) + 1));
if (($ext == "jpg") && ($_FILES["file"]["type"] == "image/jpeg") &&
($_FILES["file"]["size"] < 350000)) {
//Determine the path to which we want to save this file
$newname =”upload/”.$filename;
//Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it”s new place
if ((move_uploaded_file($_FILES[“file”][“tmp_name”],$newname))) {
echo "It”s done! The file has been saved as: ".$newname; } else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["file"]["name"]." already exists";
}
} else {
echo "Error: Only .jpg images under 350Kb are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
?>

Note: Be sure that PHP has permission to read and write to the directory in which temporary files are saved and the location in which you're trying to copy the file.

Guys, there you are. This script will upload image files with validations.
You can even add the validations by checking the header of uploading file upto first 100 bytes and make sure that file being uploaded is image file.

This example is simple way to upload file. If you re beginner in php, this should help you. In case any questions / feedback, please mail me at ninad.blog@gmail.com