Monthly archive for December 2009

How can we upload file using php?

December 31, 2009 | Filed Under PHP | 1 Comment

<html>
<head>
<title>File Upload</title>
</head>
<body>
<div>
<?php
if ( isset( $_FILES['fupload'] ) ) {

print "name: ".     $_FILES['fupload']['name'] ."<br />";
print "size: ".     $_FILES['fupload']['size'] ." bytes<br />";
print "temp name: ".$_FILES['fupload']['tmp_name'] ."<br />";
print "type: ".     $_FILES['fupload']['type'] ."<br />";
print "error: ".    $_FILES['fupload']['error'] ."<br />";

if ( $_FILES['fupload']['type'] == "image/gif" ) {

$source = $_FILES['fupload']['tmp_name'];
$target = "upload/".$_FILES['fupload']['name'];
move_uploaded_file( $source, $target );// or die ("Couldn't copy");
$size = getImageSize( $target );

$imgstr = "<p><img width=\"$size[0]\" height=\"$size[1]\" ";
$imgstr .= "src=\"$target\" alt=\"uploaded image\" /></p>";

print $imgstr;
}
}
?>
</div>
<form enctype="multipart/form-data"
action="<?php print $_SERVER['PHP_SELF']?>" method="post">
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="102400" />
<input type="file" name="fupload" /><br/>
<input type="submit" value="upload!" />
</p>
</form>
</body>
</html>

Article written by urooj

Changing time zone with date_default_timezone_set()

December 30, 2009 | Filed Under PHP | Leave a Comment

<?php
$now = time();
date_default_timezone_set('America/New York');
print date('c', $now);
date_default_timezone_set('Europe/Paris');
print date('c', $now);
?>

Article written by urooj

Authentication Over HTTP using php

December 30, 2009 | Filed Under PHP | Leave a Comment

<?
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header("WWW-Authenticate: Basic realm=\"Private Area\"");
header("HTTP/1.0 401 Unauthorized");
print "Sorry - you need valid credentials granted access to the private area!\n";
exit;
} else {
print "Welcome to the private area, {$_SERVER['PHP_AUTH_USER']}- you used {$_SERVER['PHP_AUTH_PW']} as your password.";
}
?>

Article written by urooj

How to create all and Complex type in XML?

December 30, 2009 | Filed Under XML | Leave a Comment

<strong>File: Data.xml

<?xml version=”1.0″?>
<Books xmlns=”http://www.phpinterviewquestion.com”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://www.phpinterviewquestion.com Schema.xsd”>
<Book>
<Date>2009</Date>
<Title>title 1</Title>
<Author>author 1</Author>
<ISBN>1-11111-111-1</ISBN>
<Publisher>Publisher 1</Publisher>
</Book>
<Book>
<ISBN>0-111-11111-1</ISBN>
<Title>title 2</Title>
<Author>author 2</Author>
<Date>2008</Date>
<Publisher>Publisher 2</Publisher>
</Book>
<Book>
<Publisher>Publisher 3</Publisher>
<Title>title 3</Title>
<Author>author 3</Author>
<Date>2004</Date>
<ISBN>0-11-111111-1</ISBN>
</Book>
</Books>
File: Schema.xsd
<?xml version=”1.0″?>
<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
targetNamespace=”http://www.phpinterviewquestion.com”
xmlns=”http://www.java2s.com”
elementFormDefault=”qualified”>
<xsd:element name=”Books”>
<xsd:complexType>
<xsd:sequence>
<xsd:element name=”Book” maxOccurs=”unbounded”>
<xsd:complexType>
<xsd:all>
<xsd:element name=”Title” type=”xsd:string”/>
<xsd:element name=”Author” type=”xsd:string”/>
<xsd:element name=”Date” type=”xsd:string”/>
<xsd:element name=”ISBN” type=”xsd:string”/>
<xsd:element name=”Publisher” type=”xsd:string”/>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>…………….</strong>

Article written by urooj

How to create Count(*) and existsnode() in XML?

December 30, 2009 | Filed Under XML | Leave a Comment

Count(*) and existsnode():—-
SQL> CREATE TABLE myTable
2 (id NUMBER PRIMARY KEY
3 ,doc XMLType NOT NULL)
4 XMLTYPE doc STORE AS CLOB
5 /

Table created.

SQL>
SQL> select COUNT(*) from myTable
2 where existsnode(doc, ‘/message/greeting’) = 1
3 /

COUNT(*)
———-
0

1 row selected.

SQL> drop table myTable;

Table dropped.

Article written by urooj

How create Oracle XML function ExistsNode.

December 30, 2009 | Filed Under XML | 2 Comments

Oracle XML function ExistsNode
SQL>
SQL> CREATE TABLE myTable(
2 id NUMBER PRIMARY KEY
3 ,doc XMLType NOT NULL
4 )
5 XMLTYPE doc STORE AS CLOB
6 /

Table created.

SQL>
SQL> — Demo the selfish style of invocation
SQL> select COUNT(*)
2 from myTable x
3 where x.doc.existsnode(’/message/greeting’) = 1
4 /

COUNT(*)
———-
0

1 row selected.

SQL>
SQL> drop table myTable;

Table dropped.

Article written by urooj

Whats the difference between MSIL and CIL?

December 29, 2009 | Filed Under .NET | Leave a Comment

MSIL is the name given to the intermediate language in .NET Framework Beta, 1.0 and 1.1. From version 2.0 onwards, the intermediate language is called CIL. We can say, MSIL is the old name. MSIL stands for Microsoft Intermediate Language. CIL stands for Common Intermediate Language. Its actually a low level human readable language implementation of CLI. There is not much difference between the two. Compilers like vbc.exe and csc.exe compile the code into intermediate language. CIL is the name submitted by Microsoft to the European Computer Manufacturer’s Association(ECMA) as a standard.

Article written by urooj

Whats the difference between a class and an object?

December 29, 2009 | Filed Under .NET | Leave a Comment

In any object Oriented language, an object is the backbone of everything that we see. A class is a blueprint that describes how an instance of it (object) will behave. To create a class, we define it in a “Code File”, with an extension *.cs or *.vb. We make use of the keyword class.
Example Lets create a class named Laptop public class Laptop {   private string sbrand;   public Laptop() {}   public Laptop(string name)   {     sbrand = name;   } } From our code that references this class, we write… Laptop lp = new Laptop(”Lenovo”); //Passing a variable to the class constructor

Once the class object is created, the object may be used to invoke the member functions defined within the class. We may allocate any number of objects using the new keyword. The new keyword returns a reference to an object on the heap. This reference is not to the actual object itself. The variable being refered is stored on a stack for usage in the application. When we allocate an object to a heap, its managed by the .NET runtime. The garbage collector takes care of the object by removing it from the heap, when it is no longer reachable by any part of the code.

Article written by urooj

What is the difference between Overriding and Shadowing?

December 29, 2009 | Filed Under .NET | Leave a Comment

Both Overriding and Shadowing are ways to alter the behaviour of members of a base class. Shadowing is a VB.NET concept. In C#, this concept is called Hiding, though there is a difference between the two. When we do shadowing, we provide a new implementation to the base class member without overriding it. We may shadow a base class member in a derived class, by using the keyword shadows. The access level, return type, and the signature (means the datatypes of the arguments passed & the order of the types) of the derived class members which are shadowed, may differ from the base class.

In C#, we may achieve shadowing using the keyword new. However, when Hiding in C#, the access level, the signature, return type of the derived class must be same as the base class. Overriding is the concept of providing a new implementation of derived class member as compared to its based class. In VB.NET, we do overriding using the overrides keyword, while in C#, overriding is achieved using the override keyword. For a class member to be overridable, we use the keyword virtual while defining it (in C#), and we use the keyword overridable (in VB.NET), though if we leave out specifying the overridable keyword, the member is overridable by default.

Article written by urooj

Whats the difference betweeen Structure, Class and Enumeration?

December 29, 2009 | Filed Under .NET | Leave a Comment

Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory. Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure’s constructor should always have a parameter.

So if we define the following structure struct MyStruct {   public int y,z; } and we create a structure type MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible. Class is defined using the class keyword.
A struct cannot have an instance field, whereas a class can.
class A { int x = 5; //No error … } struct { int x = 5; //Syntax Error }

A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure.
Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is “int”. Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1.
enum colors {red, green, blue, yellow}; Here, red is 0, green is 1, blue is 2 and so on. An explicit casting is required to convert an enum value to its underlying type int x = (int)colors.yellow;

Article written by urooj

© PHPInterviewQuestion.com 2009 - 2010

eXTReMe Tracker