收集PHP代码片段,PHP源代码
6月7
Laravel是一套web应用开发框架,它具有富于表达性且简洁的语法。我们相信,开发过程应该是愉悦、创造性的体验。Laravel努力剔除开发过程中的痛苦,因此我们提供了验证(authentication)、路由(routing)、session和缓存(caching)等开发过程中经常用到的工具或功能。
Laravel的目标是给开发者创造一个愉快的开发过程,并且不牺牲应用的功能性。快乐的开发者才能创造最棒的代码!为了这个目的,我们博取众框架之长处集中到Laravel中,这些框架甚至是基于Ruby on Rails、ASP.NET MVC、和Sinatra等开发语言或工具的。
Laravel是易于理解并且强大的,它提供了强大的工具用以开发大型、健壮的应用。杰出的IoC、数据库迁移工具和紧密集成的单元测试支持,这些工具赋予你构建任何应用的能力。
http://www.golaravel.com/
Laravel的目标是给开发者创造一个愉快的开发过程,并且不牺牲应用的功能性。快乐的开发者才能创造最棒的代码!为了这个目的,我们博取众框架之长处集中到Laravel中,这些框架甚至是基于Ruby on Rails、ASP.NET MVC、和Sinatra等开发语言或工具的。
Laravel是易于理解并且强大的,它提供了强大的工具用以开发大型、健壮的应用。杰出的IoC、数据库迁移工具和紧密集成的单元测试支持,这些工具赋予你构建任何应用的能力。
http://www.golaravel.com/
4月17
XTemplate是一个适用于PHP的模板引擎。它允许把HTML代码与PHP代码分开存储。XTemplate包含了许多有用的功能.
比如:嵌套的程序块,各种类型的插值变量。其代码非常简洁并且是优化的。Xtemplate是sugarCRM使用的模版技术,使用起来相对简单。
XTemplate使用了多种标签和特殊操作符支持模板,使得模板在应付复杂的数据结构时尤为健壮。这里所列出概括的几项功能,欲了解完整的细节和使用方法,请参阅XTemplate API文档。自动数组填充和作用域切换,可在子模板作用域内访问父级对象,可访问数组索引,支持数据值的简单匹配,自动渲染浮点型数组(不包含非对象的值),可执行模板中直接写好的任意语句,支持模板的配置属性,可通过配置项对象自定义模板方法,可用于服务端的JavaScript模板。
比如:嵌套的程序块,各种类型的插值变量。其代码非常简洁并且是优化的。Xtemplate是sugarCRM使用的模版技术,使用起来相对简单。
XTemplate使用了多种标签和特殊操作符支持模板,使得模板在应付复杂的数据结构时尤为健壮。这里所列出概括的几项功能,欲了解完整的细节和使用方法,请参阅XTemplate API文档。自动数组填充和作用域切换,可在子模板作用域内访问父级对象,可访问数组索引,支持数据值的简单匹配,自动渲染浮点型数组(不包含非对象的值),可执行模板中直接写好的任意语句,支持模板的配置属性,可通过配置项对象自定义模板方法,可用于服务端的JavaScript模板。
4月30
分享照片是Facebook上最流行的的功能之一。截至目前,用户已经上传超过15亿张照片,这使得Facebook成为最大的照片共享网站。对于每一个上传的照片,Facebook都生成并存储四个大小不同的图像,从而转化为共60亿张照片,总容量超过1.5PB。目前以每周220万新照片的速度增长,相当于每周要额外增加25TB存储。在高峰期每秒需要传输55万照片。这些数字对Facebook的照片存储基础设施的一个重大的挑战。
旧的 NFS 照片架构
老的照片系统架构分以下几个层:
- 上传层接收用户上传的照片并保存在 NFS 存储层。
- 照片服务层接收 HTTP 请求并从 NFS 存储层输出照片。
- NFS存储层建立在商业存储系统之上。
因为每张照片都以文件形式单独存储,这样庞大的照片量导致非常庞大的元数据规模,超过了 NFS 存储层的缓存上限,导致每次请求上传都包含多次I/O操作。庞大的元数据成为整个照片架构的瓶颈。这就是为什么 Facebook 主要依赖 CDN 的原因。为了解决这些问题,他们做了两项优化:
因为每张照片都以文件形式单独存储,大量为目录及文件在NFS 存储层上产生了大量的元数据, 这个规模的元数据量远远超过了超过了NFS 存储层的缓存上限,导致每次招聘请求会上传都包含多次I/O操作。庞大的元数据成为整个照片架构的瓶颈。这就是为什么 Facebook主要依赖 CDN 的原因。为了解决这些问题,他们做了两项优化:
- Cachr: 一个缓存服务器,缓存 Facebook 的小尺寸用户资料照片。
- NFS文件句柄缓存:部署在照片输出层,以降低 NFS 存储层的元数据开销。
4月10
开源在线学习系统moodle(企业必备软件)介绍及下载
moodle(易魔灯)一句话介绍:一个php开源在线学习,在线课堂系统,可以在线课堂,考试等模式,是企业培训,人力资源相关不可或缺的应用软件!
moodle(易魔灯)下载地址:http://download.chinaunix.net/download/0014000/13093.shtml
moodle(易魔灯)官方下载地址:http://download.moodle.org/
moodle(易魔灯)皮肤及相关插件等资源:http://www.emoodle.org/wread-2.html
Moodle 这个词本是 Modular Object-Oriented Dynamic Learning En vironment(模块化面向对象的动态学习环境)的缩写,同时Moodle 又是一个动词,用来描述一个循序渐进的过程,一个可以引导学习者不断的洞察和创造的过程。正因为如此,这个系统不仅应用于Moodle的开发,还应用于学生或教师对在线课程的学习或教学中,可以帮助教育者建立有效的在线学习社区。
Moodle是澳大利亚教师 Martin Dougiamas 基于建构主义教育理论而开发的课程管理系统, 是一个免费的开放源代码的软件, 目前在各国已广泛应用。 Moodle 这个词是 Modular Object-Oriented Dynamic Learning Environment ,即模块化面向对象的动态学习环境的缩写。是一个用来建设基于 Internet 的课程和网站的软件包。 Moodle 平台依据社会建构主义的教学思想,即教育者(老师)和学习者(学生)都是平等的主体,在教学活动中,他们相互协作,并根据自己已有的经验共同建构知识。
Moodle 平台界面简单、精巧。使用者可以根据需要随时调整界面,增减内容。课程列表显示了服务器上每门课程的描述,包括是否允许访客使用,访问者可以对课程进行分类和搜索,按自己的需要学习课程。
Moodle 平台还具有兼容和易用性。可以几乎在任何支持 PHP 的平台上安装,安装过程简单。只需要一个数据库(并且可以共享)。它具有全面的数据库抽象层,几乎支持所有的主流数据库(除了初始表定义)。利用 Moodle ,现今主要的媒体文件都可以进行传送,这使可以利用的资源极大丰富。在对媒体资源进行编辑时,利用的是用所见即所得的编辑器,这使得使用者无需经过专业培训,就能掌握 Moodle 的基本操作与编辑。 Moodle 注重全面的安全性,所有的表单都被检查,数据都被校验, cookie 是被加密的。用户注册时,通过电子邮件进行首次登陆,且同一个邮件地址不能在同一门课程中进行重复注册,所有这些,都使得 Moodle 的安全性得到了加强。目前,Moodle 项目仍然在不断的开发与完善中。
moodle(易魔灯)一句话介绍:一个php开源在线学习,在线课堂系统,可以在线课堂,考试等模式,是企业培训,人力资源相关不可或缺的应用软件!
moodle(易魔灯)下载地址:http://download.chinaunix.net/download/0014000/13093.shtml
moodle(易魔灯)官方下载地址:http://download.moodle.org/
moodle(易魔灯)皮肤及相关插件等资源:http://www.emoodle.org/wread-2.html
Moodle 这个词本是 Modular Object-Oriented Dynamic Learning En vironment(模块化面向对象的动态学习环境)的缩写,同时Moodle 又是一个动词,用来描述一个循序渐进的过程,一个可以引导学习者不断的洞察和创造的过程。正因为如此,这个系统不仅应用于Moodle的开发,还应用于学生或教师对在线课程的学习或教学中,可以帮助教育者建立有效的在线学习社区。
Moodle是澳大利亚教师 Martin Dougiamas 基于建构主义教育理论而开发的课程管理系统, 是一个免费的开放源代码的软件, 目前在各国已广泛应用。 Moodle 这个词是 Modular Object-Oriented Dynamic Learning Environment ,即模块化面向对象的动态学习环境的缩写。是一个用来建设基于 Internet 的课程和网站的软件包。 Moodle 平台依据社会建构主义的教学思想,即教育者(老师)和学习者(学生)都是平等的主体,在教学活动中,他们相互协作,并根据自己已有的经验共同建构知识。
Moodle 平台界面简单、精巧。使用者可以根据需要随时调整界面,增减内容。课程列表显示了服务器上每门课程的描述,包括是否允许访客使用,访问者可以对课程进行分类和搜索,按自己的需要学习课程。
Moodle 平台还具有兼容和易用性。可以几乎在任何支持 PHP 的平台上安装,安装过程简单。只需要一个数据库(并且可以共享)。它具有全面的数据库抽象层,几乎支持所有的主流数据库(除了初始表定义)。利用 Moodle ,现今主要的媒体文件都可以进行传送,这使可以利用的资源极大丰富。在对媒体资源进行编辑时,利用的是用所见即所得的编辑器,这使得使用者无需经过专业培训,就能掌握 Moodle 的基本操作与编辑。 Moodle 注重全面的安全性,所有的表单都被检查,数据都被校验, cookie 是被加密的。用户注册时,通过电子邮件进行首次登陆,且同一个邮件地址不能在同一门课程中进行重复注册,所有这些,都使得 Moodle 的安全性得到了加强。目前,Moodle 项目仍然在不断的开发与完善中。
1月29
7月27
PHP下载类代码
[codes=php]
<?php
//文件下载类,以下调用示例代码
$download = new download('php,exe,html', false);
if (!$download->downloadfile($filename))
{
echo $download->geterrormsg();
}
*/
class download
{
var $debug = true;
var $errormsg = '';
var $Filter = array();
var $filename = '';
var $mineType = 'text/plain';
var $xlq_filetype = array();
function download($fileFilter = '', $isdebug = true)
{
$this->setFilter($fileFilter);
$this->setdebug($isdebug);
$this->setfiletype();
}
function setFilter($fileFilter)
{
if (empty($fileFilter)) return;
$this->Filter = explode(',', strtolower($fileFilter));
}
function setdebug($debug)
{
$this->debug = $debug;
}
function setfilename($filename)
{
$this->filename = $filename;
}
function downloadfile($filename)
{
$this->setfilename($filename);
if ($this->filecheck())
{
$fn = array_pop(explode('/', strtr($this->filename, '', '/')));
header('Pragma: public');
header('Expires: 0'); // set expiration time
header('Cache-Component: must-revalidate, post-check=0, pre-check=0');
header('Content-type:'.$this->mineType);
header('Content-Length: '.filesize($this->filename));
header('Content-Disposition: attachment; filename='.$fn);
header('Content-Transfer-Encoding: binary');
readfile($this->filename);
return true;
}
else
{
return false;
}
}
function geterrormsg()
{
return $this->errormsg;
}
function filecheck()
{
$filename = $this->filename;
if (file_exists($filename))
{
$filetype = strtolower(array_pop(explode('.', $filename)));
if (in_array($filetype, $this->Filter))
{
$this->errormsg .= $filename.'不允许下载!';
if ($this->debug) exit($filename.'不允许下载!');
return false;
}
else
{
if (function_exists("mime_content_type"))
{
$this->mineType = mime_content_type($filename);
}
if (empty($this->mineType))
{
if (isset($this->xlq_filetype[$filetype])) $this->mineType = $this->
xlq_filetype[$filetype];
}
if (!empty($this->mineType)) return true;
else
{
$this->errormsg .= '获取'.$filename.'文件类型时候发生错误,或者不存在预定文件类型内';
if ($this->debug) exit('获取文件类型出错');
return false;
}
}
}
else
{
$this->errormsg .= $filename.'不存在!';
if ($this->debug) exit($filename.'不存在!');
return false;
}
}
function setfiletype()
{
$this->xlq_filetype['chm'] = 'application/octet-stream';
$this->xlq_filetype['ppt'] = 'application/vnd.ms-powerpoint';
$this->xlq_filetype['xls'] = 'application/vnd.ms-excel';
$this->xlq_filetype['doc'] = 'application/msword';
$this->xlq_filetype['exe'] = 'application/octet-stream';
$this->xlq_filetype['rar'] = 'application/octet-stream';
$this->xlq_filetype['js'] = "javascript/js";
$this->xlq_filetype['css'] = "text/css";
$this->xlq_filetype['hqx'] = "application/mac-binhex40";
$this->xlq_filetype['bin'] = "application/octet-stream";
$this->xlq_filetype['oda'] = "application/oda";
$this->xlq_filetype['pdf'] = "application/pdf";
$this->xlq_filetype['ai'] = "application/postsrcipt";
$this->xlq_filetype['eps'] = "application/postsrcipt";
$this->xlq_filetype['es'] = "application/postsrcipt";
$this->xlq_filetype['rtf'] = "application/rtf";
$this->xlq_filetype['mif'] = "application/x-mif";
$this->xlq_filetype['csh'] = "application/x-csh";
$this->xlq_filetype['dvi'] = "application/x-dvi";
$this->xlq_filetype['hdf'] = "application/x-hdf";
$this->xlq_filetype['nc'] = "application/x-netcdf";
$this->xlq_filetype['cdf'] = "application/x-netcdf";
$this->xlq_filetype['latex'] = "application/x-latex";
$this->xlq_filetype['ts'] = "application/x-troll-ts";
$this->xlq_filetype['src'] = "application/x-wais-source";
$this->xlq_filetype['zip'] = "application/zip";
$this->xlq_filetype['bcpio'] = "application/x-bcpio";
$this->xlq_filetype['cpio'] = "application/x-cpio";
$this->xlq_filetype['gtar'] = "application/x-gtar";
$this->xlq_filetype['shar'] = "application/x-shar";
$this->xlq_filetype['sv4cpio'] = "application/x-sv4cpio";
$this->xlq_filetype['sv4crc'] = "application/x-sv4crc";
$this->xlq_filetype['tar'] = "application/x-tar";
$this->xlq_filetype['ustar'] = "application/x-ustar";
$this->xlq_filetype['man'] = "application/x-troff-man";
$this->xlq_filetype['sh'] = "application/x-sh";
$this->xlq_filetype['tcl'] = "application/x-tcl";
$this->xlq_filetype['tex'] = "application/x-tex";
$this->xlq_filetype['texi'] = "application/x-texinfo";
$this->xlq_filetype['texinfo'] = "application/x-texinfo";
$this->xlq_filetype['t'] = "application/x-troff";
$this->xlq_filetype['tr'] = "application/x-troff";
$this->xlq_filetype['roff'] = "application/x-troff";
$this->xlq_filetype['shar'] = "application/x-shar";
$this->xlq_filetype['me'] = "application/x-troll-me";
$this->xlq_filetype['ts'] = "application/x-troll-ts";
$this->xlq_filetype['gif'] = "image/gif";
$this->xlq_filetype['jpeg'] = "image/pjpeg";
$this->xlq_filetype['jpg'] = "image/pjpeg";
$this->xlq_filetype['jpe'] = "image/pjpeg";
$this->xlq_filetype['ras'] = "image/x-cmu-raster";
$this->xlq_filetype['pbm'] = "image/x-portable-bitmap";
$this->xlq_filetype['ppm'] = "image/x-portable-pixmap";
$this->xlq_filetype['xbm'] = "image/x-xbitmap";
$this->xlq_filetype['xwd'] = "image/x-xwindowdump";
$this->xlq_filetype['ief'] = "image/ief";
$this->xlq_filetype['tif'] = "image/tiff";
$this->xlq_filetype['tiff'] = "image/tiff";
$this->xlq_filetype['pnm'] = "image/x-portable-anymap";
$this->xlq_filetype['pgm'] = "image/x-portable-graymap";
$this->xlq_filetype['rgb'] = "image/x-rgb";
$this->xlq_filetype['xpm'] = "image/x-xpixmap";
$this->xlq_filetype['txt'] = "text/plain";
$this->xlq_filetype['c'] = "text/plain";
$this->xlq_filetype['cc'] = "text/plain";
$this->xlq_filetype['h'] = "text/plain";
$this->xlq_filetype['html'] = "text/html";
$this->xlq_filetype['htm'] = "text/html";
$this->xlq_filetype['htl'] = "text/html";
$this->xlq_filetype['rtx'] = "text/richtext";
$this->xlq_filetype['etx'] = "text/x-setext";
$this->xlq_filetype['tsv'] = "text/tab-separated-values";
$this->xlq_filetype['mpeg'] = "video/mpeg";
$this->xlq_filetype['mpg'] = "video/mpeg";
$this->xlq_filetype['mpe'] = "video/mpeg";
$this->xlq_filetype['avi'] = "video/x-msvideo";
$this->xlq_filetype['qt'] = "video/quicktime";
$this->xlq_filetype['mov'] = "video/quicktime";
$this->xlq_filetype['moov'] = "video/quicktime";
$this->xlq_filetype['movie'] = "video/x-sgi-movie";
$this->xlq_filetype['au'] = "audio/basic";
$this->xlq_filetype['snd'] = "audio/basic";
$this->xlq_filetype['wav'] = "audio/x-wav";
$this->xlq_filetype['aif'] = "audio/x-aiff";
$this->xlq_filetype['aiff'] = "audio/x-aiff";
$this->xlq_filetype['aifc'] = "audio/x-aiff";
$this->xlq_filetype['swf'] = "application/x-shockwave-flash";
}
}
?>
[/codes]
[codes=php]
<?php
//文件下载类,以下调用示例代码
$download = new download('php,exe,html', false);
if (!$download->downloadfile($filename))
{
echo $download->geterrormsg();
}
*/
class download
{
var $debug = true;
var $errormsg = '';
var $Filter = array();
var $filename = '';
var $mineType = 'text/plain';
var $xlq_filetype = array();
function download($fileFilter = '', $isdebug = true)
{
$this->setFilter($fileFilter);
$this->setdebug($isdebug);
$this->setfiletype();
}
function setFilter($fileFilter)
{
if (empty($fileFilter)) return;
$this->Filter = explode(',', strtolower($fileFilter));
}
function setdebug($debug)
{
$this->debug = $debug;
}
function setfilename($filename)
{
$this->filename = $filename;
}
function downloadfile($filename)
{
$this->setfilename($filename);
if ($this->filecheck())
{
$fn = array_pop(explode('/', strtr($this->filename, '', '/')));
header('Pragma: public');
header('Expires: 0'); // set expiration time
header('Cache-Component: must-revalidate, post-check=0, pre-check=0');
header('Content-type:'.$this->mineType);
header('Content-Length: '.filesize($this->filename));
header('Content-Disposition: attachment; filename='.$fn);
header('Content-Transfer-Encoding: binary');
readfile($this->filename);
return true;
}
else
{
return false;
}
}
function geterrormsg()
{
return $this->errormsg;
}
function filecheck()
{
$filename = $this->filename;
if (file_exists($filename))
{
$filetype = strtolower(array_pop(explode('.', $filename)));
if (in_array($filetype, $this->Filter))
{
$this->errormsg .= $filename.'不允许下载!';
if ($this->debug) exit($filename.'不允许下载!');
return false;
}
else
{
if (function_exists("mime_content_type"))
{
$this->mineType = mime_content_type($filename);
}
if (empty($this->mineType))
{
if (isset($this->xlq_filetype[$filetype])) $this->mineType = $this->
xlq_filetype[$filetype];
}
if (!empty($this->mineType)) return true;
else
{
$this->errormsg .= '获取'.$filename.'文件类型时候发生错误,或者不存在预定文件类型内';
if ($this->debug) exit('获取文件类型出错');
return false;
}
}
}
else
{
$this->errormsg .= $filename.'不存在!';
if ($this->debug) exit($filename.'不存在!');
return false;
}
}
function setfiletype()
{
$this->xlq_filetype['chm'] = 'application/octet-stream';
$this->xlq_filetype['ppt'] = 'application/vnd.ms-powerpoint';
$this->xlq_filetype['xls'] = 'application/vnd.ms-excel';
$this->xlq_filetype['doc'] = 'application/msword';
$this->xlq_filetype['exe'] = 'application/octet-stream';
$this->xlq_filetype['rar'] = 'application/octet-stream';
$this->xlq_filetype['js'] = "javascript/js";
$this->xlq_filetype['css'] = "text/css";
$this->xlq_filetype['hqx'] = "application/mac-binhex40";
$this->xlq_filetype['bin'] = "application/octet-stream";
$this->xlq_filetype['oda'] = "application/oda";
$this->xlq_filetype['pdf'] = "application/pdf";
$this->xlq_filetype['ai'] = "application/postsrcipt";
$this->xlq_filetype['eps'] = "application/postsrcipt";
$this->xlq_filetype['es'] = "application/postsrcipt";
$this->xlq_filetype['rtf'] = "application/rtf";
$this->xlq_filetype['mif'] = "application/x-mif";
$this->xlq_filetype['csh'] = "application/x-csh";
$this->xlq_filetype['dvi'] = "application/x-dvi";
$this->xlq_filetype['hdf'] = "application/x-hdf";
$this->xlq_filetype['nc'] = "application/x-netcdf";
$this->xlq_filetype['cdf'] = "application/x-netcdf";
$this->xlq_filetype['latex'] = "application/x-latex";
$this->xlq_filetype['ts'] = "application/x-troll-ts";
$this->xlq_filetype['src'] = "application/x-wais-source";
$this->xlq_filetype['zip'] = "application/zip";
$this->xlq_filetype['bcpio'] = "application/x-bcpio";
$this->xlq_filetype['cpio'] = "application/x-cpio";
$this->xlq_filetype['gtar'] = "application/x-gtar";
$this->xlq_filetype['shar'] = "application/x-shar";
$this->xlq_filetype['sv4cpio'] = "application/x-sv4cpio";
$this->xlq_filetype['sv4crc'] = "application/x-sv4crc";
$this->xlq_filetype['tar'] = "application/x-tar";
$this->xlq_filetype['ustar'] = "application/x-ustar";
$this->xlq_filetype['man'] = "application/x-troff-man";
$this->xlq_filetype['sh'] = "application/x-sh";
$this->xlq_filetype['tcl'] = "application/x-tcl";
$this->xlq_filetype['tex'] = "application/x-tex";
$this->xlq_filetype['texi'] = "application/x-texinfo";
$this->xlq_filetype['texinfo'] = "application/x-texinfo";
$this->xlq_filetype['t'] = "application/x-troff";
$this->xlq_filetype['tr'] = "application/x-troff";
$this->xlq_filetype['roff'] = "application/x-troff";
$this->xlq_filetype['shar'] = "application/x-shar";
$this->xlq_filetype['me'] = "application/x-troll-me";
$this->xlq_filetype['ts'] = "application/x-troll-ts";
$this->xlq_filetype['gif'] = "image/gif";
$this->xlq_filetype['jpeg'] = "image/pjpeg";
$this->xlq_filetype['jpg'] = "image/pjpeg";
$this->xlq_filetype['jpe'] = "image/pjpeg";
$this->xlq_filetype['ras'] = "image/x-cmu-raster";
$this->xlq_filetype['pbm'] = "image/x-portable-bitmap";
$this->xlq_filetype['ppm'] = "image/x-portable-pixmap";
$this->xlq_filetype['xbm'] = "image/x-xbitmap";
$this->xlq_filetype['xwd'] = "image/x-xwindowdump";
$this->xlq_filetype['ief'] = "image/ief";
$this->xlq_filetype['tif'] = "image/tiff";
$this->xlq_filetype['tiff'] = "image/tiff";
$this->xlq_filetype['pnm'] = "image/x-portable-anymap";
$this->xlq_filetype['pgm'] = "image/x-portable-graymap";
$this->xlq_filetype['rgb'] = "image/x-rgb";
$this->xlq_filetype['xpm'] = "image/x-xpixmap";
$this->xlq_filetype['txt'] = "text/plain";
$this->xlq_filetype['c'] = "text/plain";
$this->xlq_filetype['cc'] = "text/plain";
$this->xlq_filetype['h'] = "text/plain";
$this->xlq_filetype['html'] = "text/html";
$this->xlq_filetype['htm'] = "text/html";
$this->xlq_filetype['htl'] = "text/html";
$this->xlq_filetype['rtx'] = "text/richtext";
$this->xlq_filetype['etx'] = "text/x-setext";
$this->xlq_filetype['tsv'] = "text/tab-separated-values";
$this->xlq_filetype['mpeg'] = "video/mpeg";
$this->xlq_filetype['mpg'] = "video/mpeg";
$this->xlq_filetype['mpe'] = "video/mpeg";
$this->xlq_filetype['avi'] = "video/x-msvideo";
$this->xlq_filetype['qt'] = "video/quicktime";
$this->xlq_filetype['mov'] = "video/quicktime";
$this->xlq_filetype['moov'] = "video/quicktime";
$this->xlq_filetype['movie'] = "video/x-sgi-movie";
$this->xlq_filetype['au'] = "audio/basic";
$this->xlq_filetype['snd'] = "audio/basic";
$this->xlq_filetype['wav'] = "audio/x-wav";
$this->xlq_filetype['aif'] = "audio/x-aiff";
$this->xlq_filetype['aiff'] = "audio/x-aiff";
$this->xlq_filetype['aifc'] = "audio/x-aiff";
$this->xlq_filetype['swf'] = "application/x-shockwave-flash";
}
}
?>
[/codes]
7月27
[codes=php]<?php
$arrFile = array('p1.jpg', 'p2.gif', 'p4.txt', 'p3.png');
/**
* 得到等比例缩放的长宽
*/
function getNewSize($maxWidth, $maxHeight, $srcWidth, $srcHeight)
{
if ($srcWidth < $srcHeight)
{
$maxWidth = ($maxHeight / $srcHeight) * $srcWidth;
}
else
{
$maxHeight = ($maxWidth / $srcWidth) * $srcHeight;
}
return array('width' => $maxWidth, 'height' => $maxHeight);
}
[/codes]
$arrFile = array('p1.jpg', 'p2.gif', 'p4.txt', 'p3.png');
/**
* 得到等比例缩放的长宽
*/
function getNewSize($maxWidth, $maxHeight, $srcWidth, $srcHeight)
{
if ($srcWidth < $srcHeight)
{
$maxWidth = ($maxHeight / $srcHeight) * $srcWidth;
}
else
{
$maxHeight = ($maxWidth / $srcWidth) * $srcHeight;
}
return array('width' => $maxWidth, 'height' => $maxHeight);
}
[/codes]
7月6
[codes=html]
很多时候,我们需要用到定时生成html页面的功能,原理简介:利用文件如index.html的最后修改时间和当前的时间做比较,当时间差超过一定间隔如2小时,则调用相关页面进行生成新页面。原始源代码如下。
ASP版本的的定时生成页面的:
<%
'不缓存
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.cachecontrol = "no-cache"
'读取最后修改时间
FPath=server.mappath("index.html")
set fso=server.CreateObject("scripting.filesystemobject")
If fso.fileExists(FPath) Then
Set f = fso.GetFile(FPath)
crdate=f.DateLastModified
end if
if DateDiff("h",crdate,now())>10 then '时间间隔大于一定值
response.write ""
end if
%>
PHP版本的的定时生成页面的:
$file = dirname(__FILE__).'/index.html';
$timex=time()-filemtime($file); //间隔时间,单位秒
if($timex>7200){ //间隔大于2小时,重新生成
echo "";
}
?>
使用方法:在网站的流量大的页面,一般为首页用 iframe 调用上面的代码即可,如插入
[/codes]%br>?phpbr>
很多时候,我们需要用到定时生成html页面的功能,原理简介:利用文件如index.html的最后修改时间和当前的时间做比较,当时间差超过一定间隔如2小时,则调用相关页面进行生成新页面。原始源代码如下。
ASP版本的的定时生成页面的:
<%
'不缓存
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.cachecontrol = "no-cache"
'读取最后修改时间
FPath=server.mappath("index.html")
set fso=server.CreateObject("scripting.filesystemobject")
If fso.fileExists(FPath) Then
Set f = fso.GetFile(FPath)
crdate=f.DateLastModified
end if
if DateDiff("h",crdate,now())>10 then '时间间隔大于一定值
response.write ""
end if
%>
PHP版本的的定时生成页面的:
$file = dirname(__FILE__).'/index.html';
$timex=time()-filemtime($file); //间隔时间,单位秒
if($timex>7200){ //间隔大于2小时,重新生成
echo "";
}
?>
使用方法:在网站的流量大的页面,一般为首页用 iframe 调用上面的代码即可,如插入
[/codes]%br>?phpbr>
6月29
5月10
PHP乱炖式的开发方式-为什么说PHP是个集中营
本文是从 Why PHP Was a Ghetto 这篇文章翻译而来。
有一天我跟在DUMBO的一个非常棒的创业公司的老板聊天,谈到为什么非PHP界的开发人员普遍轻视PHP和PHP相关社区。他提出了一个观点让我印象很深,很大程度上是因为以前从来没有听到过这样的说法。
如果你不知道大多数的程序员都会对PHP发什么样的牢骚,那么,这些牢骚差不多会像这样:
语法丑陋
缺乏其它语言都有的一些必要的特征(在5.3版本之前,没有命名空间,闭包)
不一致的函数命名、使用惯例,以及其它一些怪异的东西
过程和面向对象的杂混
基本上80-90%的PHP项目都烂如一堆狗屎
本文是从 Why PHP Was a Ghetto 这篇文章翻译而来。
有一天我跟在DUMBO的一个非常棒的创业公司的老板聊天,谈到为什么非PHP界的开发人员普遍轻视PHP和PHP相关社区。他提出了一个观点让我印象很深,很大程度上是因为以前从来没有听到过这样的说法。
如果你不知道大多数的程序员都会对PHP发什么样的牢骚,那么,这些牢骚差不多会像这样:
语法丑陋
缺乏其它语言都有的一些必要的特征(在5.3版本之前,没有命名空间,闭包)
不一致的函数命名、使用惯例,以及其它一些怪异的东西
过程和面向对象的杂混
基本上80-90%的PHP项目都烂如一堆狗屎