ACCES INTERZIS | blog de programare si securitate IT


<?php
function extract_extension($file) {
	if (strrpos($file,'.')) {
		$extension = strtolower(substr($file,strrpos($file,'.'),100));
	} else {
		$extension = '';
	}
	return($extension);
}

//example
echo extract_extension("header.inc.php");
?>

The above PHP function extracts the extension of a file. It is useful when we create upload forms or when we read dynamic a folder of files. For instance, a folder of images used by an image gallery or a folder of fonts used by a CAPTCHA.

When we create an upload form for adding images we must not allow the user to upload on our hosting server whatever his mind wants. We must make sure that what the user uploads is truely an image and not something else. Let’s say a malicious executable or scam pages which obviously can harm our server, website, image. So, each time when we develop server-side code we must keep in mind that what the user enters is not trustable. Therefore, we must add all restrictions which are required.

Usually, an image gallery feeds dynamic with the images of a folder of the hosting server. This PHP script helps us to be sure that it grabs only the images of the folder.

Post to Twitter Tweet This Post

Related posts:

Posted By: admin
Last Edit: Feb 22, 2010, 15:47

Tags
Tags:
Categories: programming


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>