How to get file extension using PHP

A simple way to debug a php application in production mode

A simple yet powerful approach to get file extension using PHP. We usually need to extract file extension from file name while uploading file so that we could generate new name and rename file to our convenience. We could create new file name using time, random or hashing, example of which has been given at the last paragraph of this post.

function get_file_extension($filename) {
    return substr($filename, strrpos($filename, '.')+1, strlen($filename)-strrpos('.', $filename));
}

Explanation:

It uses built-in substring, strrpos and strlen functions to extract file extension. A brief on these functions. Continue reading

Category: PHP | Tags: , , , , ,

WordPress + Web.config “not found” error on home page

wordpress logo

I was trying to setup wordpress on IIS when i faced this problem. I placed a web.config file with given xml code and pretty urls (permalinks) worked fine on all page except the home page. Home page gave a Not Found error while pretty permalinks worked find on all other pages. After adding the following code (given below) in system.webServer settings to web.config it worked find. In short the code given below adds index.php as a default document root. Continue reading

Category: WordPress | Tags: , , ,

How to Fix the “URL is Unreachable” Error in Facebook Comments

wordpress logo

Recently, i have been setting up the Facebook Comments plugin on my client’s server. Before trying it on live server i tried to set it up on my development server. It looked to work but with a error “Warning: http://coolum.inimist.com/?p=1 is unreachable.“ where http://coolum.inimist.com is my development server. I searched around and found an easy fix. Continue reading

Category: WordPress

Custom search with pagination using query_posts() in WordPress

The number of posts per page is set in Settings > Reading in WordPress. Once this is set, specific number of posts are shown on home page, archive pages, search results page, and so on. Continue reading

Category: WordPress

Clearing Activacollab 3.x cache through script

With upgrading to AC3 the old clear_cache_by_pattern(“*”) stopped working. There’s option at admin but i wanted a more shortcut way to clear cache, just by entering a url in browser window. Continue reading

Category: ActiveCollab3 | Tags: , ,

Creating custom authentication or one time access page in ActiveCollab

Active Collab Logo

Creating a one time authentication in ActiveCollab. The example was taken from the developer’s guide at ActiveCollab website. When i checked this one first time the file structure mentioned in the guide and the actual file structure in AC 3.1.16 looked different, and it was further changed in current 3.3, hence posting it for reference here. Continue reading

Useful function to output debug data in PHP

A simple way to debug a php application in production mode

A very useful debug function in PHP i like to use to print debug output to browser window. In some cases where i may not output the debug to browser window i use the same function to receive debug output in my email inbox.

We usually use print_r or var_dump to show debug output. This function uses print_r by default but one can use var_dump to show the output. Continue reading

Category: PHP | Tags: , , , ,

Simple captcha component for CakePHP 2.x

Captcha-Component-for-CakePHP-2.x

Captcha-Component-for-CakePHP-2.x

Updated on – April 12, 2013

  • Random captcha images are possible. Set “theme”=>”random” in $settings variable of CaptchaComponent.php or in Controller when loading captcha component.
  • Can’t Read? Reload is possible now. A working piece of jQuery code is included in view file add.ctp. Be sure to include jquery library, such as https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js to make Reloading of captcha working

Updated on – April 09, 2013

Download Captcha Component for Cakephp 2.x
Download Captcha Component for Cakephp 1.x

How to make it working

Download attached zip file and extract. Copy all files placed in app folder to their corresponding locations. Continue reading

Category: CakePHP | Tags: , ,

Capitalize, Uppercase, Lowercase Online

Different code editors do have different keyboard shortcuts to do Capitalize, Uppercase and Lowercase of text. Generally, i use EditPlus as code editor which has shortcuts for uppercase and lowercase but it does not seem to have a shortcut or even option to do capitalization of text content. Invent of this tool resulted from this particular necessity :) Continue reading

Category: Tools | Tags: , , , ,

How to know whether an element existed with jQuery

For the reference. In general javascript we can check for the existence of an element using the method below:

if(document.getElementById('element_id')) {
  //element exists
} else  {
  //element does not exist
}

Continue reading