Wednesday, October 6, 2010

php: upload file- with same name from client to server

HTML CODE:
-------------------------------------------------------------------------------


Choose a file to upload:



-------------------------------------------------------------------------------
PHP CODE
=============================================
PHP Code:

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}

=============================================
Here is a brief description of the important parts of the above code:

* enctype="multipart/form-data" - Necessary for our to-be-created PHP file to function properly.
* action="uploader.php" - The name of our PHP page that will be created, shortly.
* method="POST" - Informs the browser that we want to send information to the server using POST.
* input type="hidden" name="MA... - Sets the maximum allowable file size, in bytes, that can be uploaded. This safety mechanism is easily bypassed and we will show a solid backup solution in PHP. We have set the max file size to 100KB in this example.
* input name="uploadedfile" - uploadedfile is how we will access the file in our PHP script.

Save that form code into a file and call it upload.html. If you view it in a browser it should look like this:
-----------------------------------------
The $_FILES array is where PHP stores all the information about files. There are two elements of this array that we will need to understand for this example.

* uploadedfile - uploadedfile is the reference we assigned in our HTML form. We will need this to tell the $_FILES array which file we want to play around with.
* $_FILES['uploadedfile']['name'] - name contains the original path of the user uploaded file.
* $_FILES['uploadedfile']['tmp_name'] - tmp_name contains the path to the temporary file that resides on the server. The file should exist on the server in a temporary directory with a temporary name.

Now we can finally start to write a basic PHP upload manager script! Here is how we would get the temporary file name, choose a permanent name, and choose a place to store the file.

Thursday, September 2, 2010

Dojo

After Zend its time to Dojo Frame work.

-------------------------------------------------------
Get Started Using Dojo 1.5.0
Quick Start: No Download Required


-------------------------------------------------------
Mastering Dojo JavaScript and Ajax Tools for Great Web Experiences

Thursday, June 10, 2010

Using floor and time to calculate number of days elapsed from UNIX timestamp


Finding out the number of days elapsed from a UNIX timestamp is actually pretty straightforward. If you only know two dates then first you’ll need to convert the date to a UNIX timestamps and then subtract the most recent timestamp from the older timestamp like this:
$old_timestamp = 1102971600;
$elapsed_seconds = time() - $old_timestamp;
print ‘Seconds elapsed since ‘ . date(“m-d-Y H:i:s”,$old_timestamp) . “: $elapsed_seconds”;
?>

Now, let’s convert those seconds to days using the floor() function, by just adding the following code to the code above:
/*
divide #seconds by 60 for minutes
divide #of minutes by 60 for hours
divide #of hours by 24 for days
use floor to get integer for day
*/
$elapsed_days = floor(($elapsed_seconds / 60) / 60 / 24);
print “
Number of days elapsed: $elapsed_days”;

Tuesday, February 2, 2010

numbers to words (indian rupess)

start php tag

class NumberToWord
{

/**
* @param int number
* @return string input inmber in words
*/
public function numberToWord($number)
{
if (($number < 0) || ($number > 999999999))
{
throw new Exception("Number is out of range");
}
/*
* crore
*/
$croreNumber = floor($number / 10000000);
$number -= $croreNumber * 10000000;
/**
* lakhs
*/
$lakhNumber = floor($number / 100000);
$number -= $lakhNumber * 100000;
/**
* Thousands (kilo)
*/
$kiloNumber = floor($number / 1000);
$number -= $kiloNumber * 1000;
/**
* Hundreds (hecto)
*/
$hectoNumber = floor($number / 100);
$number -= $hectoNumber * 100;
/**
* Tens (deca)
*/
$decaNumber = floor($number / 10);
/**
* Ones (single digit/ Number)
*/
$onesNumber = $number % 10;
$result = "";

if ($croreNumber)
{
$result .= (empty($result) ? "" : " ") .
$this->numberToWord($croreNumber) . " Crore ";
}

if ($lakhNumber)
{
$result .= (empty($result) ? "" : " ") .
$this->numberToWord($lakhNumber) . " Lakh ";
}

if ($kiloNumber)
{
$result .= (empty($result) ? "" : " ") .
$this->numberToWord($kiloNumber) . " Thousand ";
}

if ($hectoNumber)
{
$result .= (empty($result) ? "" : " ") .
$this->numberToWord($hectoNumber) . " Hundred ";
}

$ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve",
"Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eightteen","Nineteen");

$tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
"Seventy", "Eigthy", "Ninety");

if ($decaNumber || $onesNumber)
{
if (!empty($result))
{
$result .= " ";
}

if ($decaNumber < 2)
{
$result .= $ones[$decaNumber * 10 + $onesNumber];
}
else
{
$result .= $tens[$decaNumber];
if ($onesNumber)
{ $result .= " " . $ones[$onesNumber]; }
}
}

if (empty($result))
{
$result = "zero";
}

return $result;
}
}

$number = 100000000;
$helperWords = new NumberToWord;
$wordString = $helperWords->numberToWord($number);
echo "Number Converted to words:$wordString";
?>

Friday, January 15, 2010

fpdf number_format()

number_format

(PHP 4, PHP 5)

number_format — Format a number with grouped thousands

string number_format ( float $number , int $decimals , string $dec_point , string $thousands_sep )
----------------------------------------------------------------------------------------------

number

The number being formatted.
decimals

Sets the number of decimal points.
dec_point

Sets the separator for the decimal point.
thousands_sep

Sets the thousands separator.

Only the first character of thousands_sep is used. For example, if you use bar as thousands_sep on the number 1000, number_format() will return 1b000.

----------------------------------------------------------------------------------------------


Example #1 number_format() Example

For instance, French notation usually use two decimals, comma (',') as decimal separator, and space (' ') as thousand separator. This is achieved with this line :

$number = 1234.56;

// english notation (default)
$english_format_number = number_format($number);
// 1,235

// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56

$number = 1234.5678;

// english notation without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57

?>

How to install Google Chrome in Fedora 10 or Fedora 11

To install chromium, create a chromium.repo file in your /etc/yum.repos.d directory.

vim /etc/yum.repos.d/chromium.repo
--------------------------------------------------------------------------------------
Then fill it up with this:-

[chromium]
name=Chromium Test Packages
baseurl=http://spot.fedorapeople.org/chromium/F$releasever/
enabled=1
gpgcheck=0
--------------------------------------------------------------------------------------
After that, just yum install chromium
--------------------------------------------------------------------------------------
[root@atreides ~]# yum install chromium
Loaded plugins: fastestmirror, presto, refresh-packagekit
Loading mirror speeds from cached hostfile
* fedora: mirror.oscc.org.my
* rpmfusion-free: mirror.transact.net.au
* rpmfusion-free-updates: mirror.transact.net.au
* rpmfusion-nonfree: mirror.transact.net.au
* rpmfusion-nonfree-updates: mirror.transact.net.au
* updates: ftp.riken.jp
chromium | 1.2 kB 00:00
chromium/primary | 2.4 kB 00:00
chromium 7/7
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package chromium.i586 0:3.0.191.0-0.1.20090628svn19474.fc11 set to be updated
--> Processing Dependency: libv8.so.0 for package: chromium-3.0.191.0-0.1.20090628svn19474.fc11.i586
--> Running transaction check
---> Package v8.i586 0:1.2.9-1.20090626svn2284.fc11 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
chromium i586 3.0.191.0-0.1.20090628svn19474.fc11 chromium 11 M
Installing for dependencies:
v8 i586 1.2.9-1.20090626svn2284.fc11 chromium 858 k

Transaction Summary
================================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 12 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 12 M
(1/2): chromium-3.0.191.0-0.1.20090628svn19474.fc11.i586 | 11 MB 01:11
(2/2): v8-1.2.9-1.20090626svn2284.fc11.i586.rpm | 858 kB 00:06
--------------------------------------------------------------------------------
Total 149 kB/s | 12 MB 01:19
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : v8-1.2.9-1.20090626svn2284.fc11.i586 1/2
Installing : chromium-3.0.191.0-0.1.20090628svn19474.fc11.i586 2/2

Installed:
chromium.i586 0:3.0.191.0-0.1.20090628svn19474.fc11

Dependency Installed:
v8.i586 0:1.2.9-1.20090626svn2284.fc11

Complete!

Thursday, August 13, 2009

PHP Script showing Google map route b/w Bangalore to Bagalkote

http://php.example.org/Implementaion/map.php
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
iframe width="325" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
src="http://maps.google.co.in/maps?f=d&source=s_d&saddr=Bangalore&daddr=Bagalkot,+Karnataka&
hl=en&geocode=%3BFbP29gAdcwiDBA&mra=ls&sll=13.019945,77.624588&sspn=0.288335,0.441513&
ie=UTF8&ll=14.577975,76.6477&spn=3.22181,1.903&output=embed">
/iframe
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

style="color:#0000FF;text-align:left">View Larger Map