2009年1月22日星期四

2009年1月3日星期六

PHP Force downloading of a file

Forces a user to download a file, for e.g you have an image but you want the user to download it instead of displaying it in his browser.

header("Content-type: application/octet-stream");


// displays progress bar when downloading (credits to Felix ;-))
header("Content-Length: " . filesize('myImage.jpg'));


// file name of download file
header('Content-Disposition: attachment; filename="myImage.jpg"');

// reads the file on the server
readfile('myImage.jpg');

PHP snippets

Before any database operations:

function check_input($value)
{
// 去除斜杠
if (get_magic_quotes_gpc())
{ $value = stripslashes($value); }
// 如果不是数字则加引号
if (!is_numeric($value))
{ $value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

2009年1月1日星期四

Economic growth in 2009, winners and losers.

FW from the Economist
The ten fastest and slowest, growing economies in 2009.

ICELAND will b ethe world's worst economic performer in the coming year, according to the Economist Intelligence Unit, a sister organisation to The Economist. The tiny country will see growth shrink by nearly 10% following the spectacular collapse of its banks in the global financial crisis. Countries with free-falling currencies, burst housing bubbles and a heavy reliance of finance and trade will also suffer. Qatar will grow by over 13%, and many sub-Saharan Arican countries will aslo perform strongly. China is still in the top ten but will grow at a considerably more sedate pace than in recent years. Global growth is set to be a feeble 0.9%.