Binod's Blog

Tag: Tips n Tricks

Get File Extension in PHP

by on Aug.28, 2011, under PHP, Tips & Tricks, Tutorial, Web Designing

Today I will be sharing some piece of code for getting the real file extension of the uploaded file. I was working on the CMS few days back and there I made the file upload section but I didn’t checked which type of file is been uploaded. During my testing phase I just tested for jpeg file.[ as it was my target]. I hosted it over my server, it was working fine…

The next day, I received a wall post on Facebook from my friend. Binod, you got a security flaw in ur script. I checked it. What he did was he uploaded his scripted file [PHP file] thru that upload section and started to traverse my whole server files.

Then, I realized I need to check the extension of the file and to block the unwanted extension. (E.g. “php” from “myscript.php”).

Here is some piece of code of my CMS that will be beneficial for the users.

//for the upload page

<input type=”file” name=”myfile” />

//for the submit page

$fileatt = $_FILES['myfile']['tmp_name'];
$filename = $_FILES['myfile']['name'];

//there are Five ways that may be helpful

// 1. The “explode/end” approach
$ext = end(explode(‘.’, $filename));

// 2. The “strrchr” approach
$ext = substr(strrchr($filename, ‘.’), 1);

// 3. The “strrpos” approach
$ext = substr($filename, strrpos($filename, ‘.’) + 1);

// 4. The “preg_replace” approach
$ext = preg_replace(‘/^.*\.([^.]+)$/D’, ‘$1′, $filename);

//5. The “pathinfo” approch
$ext = pathinfo($filename, PATHINFO_EXTENSION);

//Checking The uploaded
if(($ext==”jpg”)||($ext==”jepg”)||($ext==”gif”)||($ext==”png”)){
// Uploading and processing script
}else{
// Error script amd msg
}

Leave a Comment :, , more...

Shortcut keys in different versions Microsoft Windows.

by on May.08, 2011, under General, Technology, Tips & Tricks, Tutorial

This is a listing of some common shortcut keys in different versions Microsoft Windows.

Some shortcut keys below are not supported in all versions of Windows.

The shortcut keys on this page are only applicable for Windows in general.

Shortcut Key Supported Window Versions Short Key Description
Alt + (double-click) 95, 98, ME, NT, 2000, XP, Vista, Win 7 Open Properties dialog of selected item.
Alt + Enter 95, 98, ME, NT, 2000, XP, Vista, Win 7 Opens properties window of selected item.
Alt + Esc 95, 98, ME, NT, 2000, XP, Vista, Win 7 Switch Between open tasks available on the taskbar.
Alt + F4 95, 98, ME, NT, 2000, XP, Vista, Win 7 Close the top (focused) window.
Alt + Tab 95, 98, ME, NT, 2000, XP, Vista, Win 7 Switch between open windows.
Alt + Tab + Shift 95, 98, ME, NT, 2000, XP, Vista, Win 7 Switch between open windows, backward.
Ctrl + Alt + Delete (or Del) 95, 98, ME, NT, 2000, XP, Vista, Win 7 Bring up the Windows Task Manager, or reboot computer.
Ctrl + Esc 95, 98, ME, NT, 2000, XP, Vista, Win 7 Bring up the Windows Start menu.
Ctrl + ‘+’ (‘+’ key on the keypad) 98, ME, NT, 2000, XP, Vista, Win 7 Autofit the widths of all columns (if available) in current window.
Ctrl + F4 95, 98, ME, NT, 2000, XP, Vista, Win 7 Close sub window/tab.
Ctrl + Tab 95, 98, ME, NT, 2000, XP, Vista, Win 7 Switch between existing tabs (within a window).
Ctrl + Tab + Shift 95, 98, ME, NT, 2000, XP, Vista, Win 7 Switch between existing tabs (within a window), backward
F1 95, 98, ME, NT, 2000, XP, Vista, Win 7 Open Help for Windows or focused application.
F2 95, 98, ME, NT, 2000, XP, Vista, Win 7 Rename.
F3 95, 98, ME, NT, 2000, XP, Vista, Win 7 Find/Search.
F4 95, 98, ME, NT, 2000, XP, Vista, Win 7 Select drives or display the list of drives
F5 95, 98, ME, NT, 2000, XP, Vista, Win 7 Refresh.
F6 95, 98, ME, NT, 2000, XP, Vista, Win 7 Switch focus to the address bar (if exists).
F10 95, 98, ME, NT, 2000, XP, Vista, Win 7 Switch focus to the top menu bar.
Shift + F10 95, 98, ME, NT, 2000, XP, Vista, Win 7 Same as mouse right-click on the select item.
Print Screen 95, 98, ME, NT, 2000, XP, Vista, Win 7 Capture a screenshot of the entire desktop to clipboard.
Print Screen + Alt 95, 98, ME, NT, 2000, XP, Vista, Win 7 Capture a screenshot of just the top(focused) window to clipboard.
Shift + Delete (or Del) 95, 98, ME, NT, 2000, XP, Vista, Win 7 Permanently delete selected file(s)/folder(s) (bypass recycle bin)
Shift (hold while inserting an audio CD to drive) 95, 98, ME, NT, 2000, XP, Vista, Win 7 Prevent autoplay.
* (keypad) on Windows Explorer. 95, 98, ME, NT, 2000, XP, Vista, Win 7 Expand all sub-directories from the selected item.
+ (keypad) on Windows Explorer. 95, 98, ME, NT, 2000, XP, Vista, Win 7 Expand only the first level of selected item.
- (keypad) on Windows Explorer. 95, 98, ME, NT, 2000, XP, Vista, Win 7 Collapse

Most keyboards have a Windows Key (key with a Windows icon). This key provides additional shortcuts for Microsoft Windows. Below is a list of the shortcut keys by combining the Windows key and other keys.

Shortcut Keys Description
WINDOWS-KEY Bring up the Windows Start menu.
WINDOWS-KEY + F1 Bring up the Windows Help.
WINDOWS-KEY + e Open Microsoft Explorer.
WINDOWS-KEY + f Windows Search.
WINDOWS-KEY + Ctrl + f Search for computers
WINDOWS-KEY + d Minimizes all and bring up desktop, or restore all
WINDOWS-KEY + l Lock the computer (Windows XP & newer).
WINDOWS-KEY + m Minimizes all windows.
WINDOWS-KEY + Shift + M Restore all. Opposite with WINDOWS-KEY + M and WINDOWS-KEY + D.
WINDOWS-KEY + r Open the run window.
WINDOWS-KEY + u Utility Manager.
WINDOWS-KEY + Tab Cycle through the programs on task bar.
WINDOWS-KEY + Pause/Break Open the System Properties window.
1 Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...