Skip to content

Instantly share code, notes, and snippets.

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
--Do not remove this if you are using--
Original Author: Remiz Rahnas
Original Author URL: http://www.htmlremix.com
Published date: 2008/09/24
Changes by Nick Fetchak:
- IE8 standards mode compatibility
- VML elements now positioned behind original box rather than inside of it - should be less prone to breakage
Published date : 2009/11/18
$load = sys_getloadavg();
if ($load[0] > 80) {
header('HTTP/1.1 503 Too busy, try again later');
die('Server too busy. Please try again later.');
}
/*
This is a function which returns three samples of the “load” on a system. Load is the number of processes in the system run queue. The 3 items in the array are the average load for the past 1, 5 and 15 minutes. The PHP Manual shows a great usage of this:
*/
//for a number of classes to load automatically
//We can define the following function in our file
function __autoload($class_name)
{
$path = str_replace("_", "/", $class_name);
require_once $path.".php";
}
if(navigator.appName=="Microsoft Internet Explorer" ) {
return false;
}
else {
return this.init(canvasId,displayRadius,skinId,showSecondHand,gmtOffset);
}
@shameerc
shameerc / gist:662115
Created November 4, 2010 04:02
Avoid double encoding special characters
//Use the fourth argument as false
echo htmlentities($foo, ENT_COMPAT, 'UTF-8',false);
@shameerc
shameerc / pdo_conn_select.php
Created November 10, 2010 07:24
PHP Pdo class
<?
$dsn = 'mysql:dbname=test;host=hostname';
$user = 'username';
$password = 'Password';
try {
$dbh = new PDO($dsn, $user, $password);
echo "Connected";
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
@shameerc
shameerc / simple_labda.php
Created December 2, 2010 04:04
basic example for lambda function
<?php
$sum = function($a,$b){
return $a+$b;
};
echo $sum(2,5);
?>
@shameerc
shameerc / ie_hack.css
Created December 7, 2010 10:42
Css hacks for IE
div.example {
width: 300px; /* applied in all browsers */
*width: 350px; /* applied to IE6 and IE7 only */
_width: 360px; /* applied to IE6 only */
}
@shameerc
shameerc / validate_email.php
Created December 10, 2010 05:47
Simple email valiation
<?php
// This function uses simple filter_var function
// instead of regular expression to validate email
// @param string email Email address to be validated
function validateEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
?>