Author Archive

Request Class Details

For importing Request Class use following statement
use Symfony\Component\HttpFoundation\Request;

Following statement creates object of class “Request”
$request = Request::createFromGlobals();

// the URI being requested (e.g. /about) minus any query parameters
Every Index of $_SERVER global variable can be accessed using Request object with using get method
so for example to get $_SERVER['PATH_INFO'] using Request Object use following statement.

$request->getPathInfo();

// retrieve GET and POST variables respectively
$request->query->get(‘foo’);
$request->request->get(‘bar’);

// retrieves an instance of UploadedFile identified by foo
$request->files->get(‘foo’);

$request->getMethod(); // GET, POST, PUT, DELETE, HEAD
$request->getLanguages(); // an array of languages the client accepts

List of functions available in Request class can be accessed via following link\

http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html

1 Comment more...

File size limit exceeded linux error

This error can be fixed by checking command uname -a.
Here it will display max limits assigned to various resources.
If even after assigning limits it is giving error it means one of your logs is having size which has exceeded the limit. Try by clearing your logs then everything must work fine.

1 Comment more...

To check whether an element exists using jQuery

To check whether element is present or not use following code in jQuery:-

If we use following code for checking tag it will always return true as
jQuery always returns object.

if($(‘checkbox’)){

}

Correct way to do this is as follows:-

if ($(‘checkbox’).length > 0) {

}


To get Linux OS release

To get Linux OS release, give either of the following commands

1.$ uname -r
2.$ cat /proc/version


Code for resumable download

Another piece of code for PHP developers, useful in open source development.

Following is the function for application that needs functionality of resumable download.

public static function dl_file_resumable($file, $is_resume=TRUE)
{
//First, see if the file exists
if (!is_file($file))
{
die(“404 File not found!“);
}

//Gather relevent info about file
$size = filesize($file);
$fileinfo = pathinfo($file);

//workaround for IE filename bug with multiple periods / multiple dots in filename
//that adds square brackets to filename – eg. setup.abc.exe becomes setup[1].abc.exe
$filename = (strstr($_SERVER['HTTP_USER_AGENT'], ‘MSIE’)) ?
preg_replace(‘/\./’, ‘%2e’, $fileinfo['basename'], substr_count($fileinfo['basename'], ‘.’) – 1) :
$fileinfo['basename'];

$file_extension = strtolower($path_info['extension']);

//This will set the Content-Type to the appropriate setting for the file
switch($file_extension)
{
case ‘zip’: $ctype=’application/zip’; break;
default: $ctype=’application/force-download’;
}

//check if http_range is sent by browser (or download manager)
if($is_resume && isset($_SERVER['HTTP_RANGE']))
{
list($size_unit, $range_orig) = explode(‘=’, $_SERVER['HTTP_RANGE'], 2);
if ($size_unit == ‘bytes’)
{
//multiple ranges could be specified at the same time, but for simplicity only serve the first range
//http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
list($range_from, $extra_ranges) = explode(‘,’, $range_orig, 2);
}
else
{
$range_from = ”;
}
}
else
{
$range_from = ”;
}

//figure out download piece from range (if set)
list($seek_start, $seek_end) = explode(‘-’, $range_from, 2);

//set start and end based on range (if set), else set defaults
//also check for invalid ranges.
$seek_end = (empty($seek_end)) ? ($size – 1) : min(abs(intval($seek_end)),($size – 1));
$seek_start = (empty($seek_start) || $seek_end 0 || $seek_end < ($size – 1))
{
header(‘HTTP/1.1 206 Partial Content’);
}

header(‘Accept-Ranges: bytes’);
header(‘Content-Range: bytes ‘.$seek_start.’-’.$seek_end.’/’.$size);
}

//headers for IE Bugs (is this necessary?)
//header(“Cache-Control: cache, must-revalidate”);
//header(“Pragma: public”);

header(‘Content-Type: ‘ . $ctype);
header(‘Content-Disposition: attachment; filename=”‘ . $filename . ‘”‘);
header(‘Content-Length: ‘.($seek_end – $seek_start + 1));

//open the file
$fp = fopen($file, ‘rb’);
//seek to start of missing part
fseek($fp, $seek_start);

//start buffered download
while(!feof($fp))
{
//reset time limit for big files
set_time_limit(0);
print(fread($fp, 1024*8));
flush();
ob_flush();
}

fclose($fp);
}


To get data from POST body in PHP

This may look a very simple and small piece of code, but it took me ages to work on this one and get it in a proper format hence thought of sharing it with all. I used this line of code to get the data from POST body. I hope this will help you with your PHP Development.

file_get_contents(‘php://input’);


Introduction to HTML 5 (part 1 of 10)

HTML 5

HTML is always considered as one of the important aspects of web development. Here, we are discussing about HTML5.

HTML5 which is currently under development is the next major revision of the HTML standard. Like its immediate Predecessors HTML4.01 and XHTML 1.1 , HTML5 is a standard for structuring and presenting content on world wide web.

This new standard incorporates features like video playback , drag and drop , geolocation, data storage , visiting websites offline , forms and many more.

Here is a brief history of HTML5.

HTML5 which is currently under development is the next major revision of the HTML standard.

There was never any such thing as HTML 1

The first official specification was HTML 2.0, published by the IETF, the Internet Engineering Task Force.

Later on the role of the IETF was superceded by the W3C, the World Wide Web Consortium, where subsequent iterations of the HTML standard have been published.

In the latter half of nineties HTML 4.01 was published.

After HTML 4.01, the next revision to the language was called XHTML 1.0

The content of the XHTML 1.0 specification was identical to that of HTML 4.01. No new elements or attributes were added.

The only difference was in the syntax of the language.

Valid XHTML 1.0 document requires all tags and attributes to be in lowercase. All attributes must be quoted.All elements must have a closing tag.

These rules were similar to that of XML.So they were moving towards XML more.

Then the W3C published XHTML 1.1.

It seemed as if the W3C were losing touch with the day-to-day reality of publishing on the web as they were moving towards XML.

They began working on XHTML 2

XHTML 2 wasn’t going to be backwards compatible with existing web content or even previous versions of HTML

Representatives from Opera, Apple and Mozilla were unhappy with this direction.

They formed their own group: the Web Hypertext Application Technology Working Group, or WHATWG

They started working on HTML Standard and came out with new revision HTML5

The W3C uses a consensus-based approach: issues are raised, discussed, and voted on.

At the WHATWG, issues are also raised and discussed, but the final decision on what
goes into a specification rests with the editor. The editor is Ian Hickson.

While HTML5 was being developed at the WHATWG, the W3C continued working on XHTML 2

Later on W3C admitted that the attempt to move the web from HTML to XML just wasn’t working.

Rather than start from scratch, they wisely decided that the work of the WHATWG should be used as the basis for any future version of HTML.

Later on W3C announced that they will stop working on XHTML 2 and they will support WHATWG.

There are two groups working on HTML5. The WHATWG is creating an HTML5 specification using its process of “commit then review.” The W3C HTML Working Group is taking that specification and putting it through its process of “review then
commit.”

TechJini Solutions
TechJini Solutions is Bangalore, India based company working in the areas of software product engineering services and creating next generation software products that bring real business value. We take pride in our philosophy of taking on challenging problems and providing innovative and outstanding solutions. We are proud to develop applications on different mobile/tablet platforms including iPhone, iPad, BlackBerry and Android.

Next time, we will look at Forms in HTML 5. Feel free to email me for more details – avidnyat@techjini.com


  • TechJini Solutions

  • © Copyright 2009 TechJini Solutions Private Limited. All Rights Reserved
    iDream theme by Templates Next | Powered by WordPress