php文件上传代码(支持文件批量上传)
本款文件上传类,默认是上传单文件的,我们只要修改$inputname ='files'为你的表单名就可以方便的实现批量文件上传了。 $savename = ''保存文件名, $alowexts = array()设置允许上传的类型,$savepath = ''保存路径。
*/
代码如下 | 复制代码 |
class upload function __construct($inputname ='files', $savepath = '', $savename = '', $alowexts = array(),$maxsize = 1024000) if(!make_dir($this->savepath)) if(move_uploaded_file($tmp_name,$this->savepath.$savename) || @copy($tmp_name,$this->savepath.$savename)) function isuploadedfile($file) //去掉系统自带的反斜线 function error() } |
//使用方法
new upload();
<?php教程
/*
* 模板分页类,源于easp教程的数据库教程分页方法,算是easp分页的的php独立版
* 支持动态和静态分页方式
* * page([总记录数=1],[分页大小=20],[当前页=1],[显示页数=6],[分页参数='page'],[分页链接=当前页面],[是否静态=false])
* 动态:
* 简单用法:
* $page = new page(50);
* $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品 当前第 {pageindex} 页 / 共 {pagecount} 页 分页: {first}{prev} {list} {next}{last} 转到 {jump} 页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
* echo $page->getpager('zjj');
* 全参数用法:
* $page = new page(50,20,1,6,'page','prrr.php',false);
* $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品 当前第 {pageindex} 页 / 共 {pagecount} 页 分页: {first}{prev} {list} {next}{last} 转到 {jump} 页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
* echo $page->getpager('zjj');
* 静态:
* $page = new page(50,20,1,6,'page','prrr{page}.html',true);
* $page->setpager('zjj','<div class="newpager">共有{recordcount} 个商品 当前第 {pageindex} 页 / 共 {pagecount} 页 分页: {first}{prev} {list} {next}{last} 转到 {jump} 页</div>',array("listlong"=>"6","first"=>"首页","last"=>"尾页","prev"=>"上一页","next"=>"下一页","list"=>"第*页","jump"=>"select"));
* echo $page->getpager('zjj');
*/
class page {
private $page_size; //每页显示的条目数
private $total_size; //总条目数
private $current_page; //当前被选中的页
private $sub_pages; //每次显示的页数
private $total_pages; //总页数
private $page_tpl = array (); // 分页模板
private $pageparam;
private $pagelink;
private $static;
function __construct($total_size = 1, $page_size = 20, $current_page = 1, $sub_pages = 6, $pageparam = 'page', $pagelink = '', $static = false) {
$this->page_size = intval ( $page_size );
$this->total_size = intval ( $total_size );
if (! $current_page) {
$this->current_page = 1;
} else {
$this->current_page = intval ( $current_page );
}
$this->total_pages = ceil ( $total_size / $page_size );
$this->sub_pages = intval ( $sub_pages );
$this->pageparam = $pageparam;
$this->pagelink = (empty ( $pagelink ) ? $_server ["php_self"] : $pagelink);
$this->static = $static;
$this->page_tpl ['default'] = array ('tpl' => '<div class="pager">{first}{prev}{liststart}{list}{listend}{next}{last} 跳转到{jump}页</div>', 'config' => array () );
}
public function __set($param, $value) {
$this->$param = $value;
}
public function __get($param) {
return $this->$param;
}
/*
__destruct析构函数,当类不在使用的时候调用,该函数用来释放资源。
*/
function __destruct() {
unset ( $page_size ); //每页显示的条目数
unset ( $total_size ); //总条目数
unset ( $current_page ); //当前被选中的页
unset ( $sub_pages ); //每次显示的页数
unset ( $total_pages ); //总页数
unset ( $page_tpl ); // 分页模板
unset ( $pageparam ); //分页参数,默认page
unset ( $pagelink );
unset ( $static );
}
private function urlparameters($url = array()) {
foreach ( $url as $key => $val ) {
if ($key != $this->pageparam)
$arg [] = $key . '=' . $val;
}
$arg [] = $this->pageparam . '=*';
if ($this->static)
return str_replace ( '{page}', '*', $this->pagelink );
else
return $this->pagelink . '?' . implode ( '&', $arg );
}
public function setpager($tpl_name = 'default', $tpl = '', $config = array()) {
if (empty ( $tpl ))
$tpl = $this->page_tpl ['default'] ['tpl'];
if (empty ( $config ))
$config = $this->page_tpl ['default'] ['config'];
$this->page_tpl [$tpl_name] = array ('tpl' => $tpl, 'config' => $config );
}
public function getpager($tpl_name = 'default') {
$this->getcurrentpage ();
return $this->pager ( $this->page_tpl [$tpl_name] );
}
public function getcurrentpage() {
$this->current_page = ($_get [$this->pageparam] <= intval ( $this->total_pages ) ? ($_get [$this->pageparam] < 1 ? 1 : $_get [$this->pageparam]) : intval ( $this->total_pages ));
}
public function pager($page_tpl = '') {
if (empty ( $page_tpl ))
$page_tpl = $this->page_tpl ['default'];
$cfg = array ('recordcount' => intval ( $this->total_size ), 'pageindex' => intval ( $this->current_page ), 'pagecount' => intval ( $this->total_pages ), 'pagesize' => intval ( $this->page_size ), 'listlong' => intval ( $this->sub_pages ), 'listsidelong' => 2, 'list' => '*', 'currentclass' => 'current', 'link' => $this->urlparameters ( $_get ), 'first' => '«', 'prev' => '‹', 'next' => '›', 'last' => '»', 'more' => '...', 'disabledclass' => 'disabled', 'jump' => 'input', 'jumpplus' => '', 'jumpaction' => '', 'jumplong' => 50 );
if (! empty ( $page_tpl ['config'] )) {
foreach ( $page_tpl ['config'] as $key => $val ) {
if (array_key_exists ( $key, $cfg ))
$cfg [$key] = $val;
}
}
$tmps教程tr = $page_tpl ['tpl'];
$pstart = $cfg ['pageindex'] - (($cfg ['listlong'] / 2) + ($cfg ['listlong'] % 2)) + 1;
$pend = $cfg ['pageindex'] + $cfg ['listlong'] / 2;
if ($pstart < 1) {
$pstart = 1;
$pend = $cfg ['listlong'];
}
if ($pend > $cfg ['pagecount']) {
$pstart = $cfg ['pagecount'] - $cfg ['listlong'] + 1;
$pend = $cfg ['pagecount'];
}
if ($pstart < 1)
$pstart = 1;
for($i = $pstart; $i <= $pend; $i ++) {
if ($i == $cfg ['pageindex'])
$plist .= '<span class="' . $cfg ['currentclass'] . '" >' . str_replace ( '*', $i, $cfg ['list'] ) . '</span> ';
else
$plist .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
}
if ($cfg ['listsidelong'] > 0) {
if ($cfg ['listsidelong'] < $pstart) {
for($i = 1; $i <= $cfg ['listsidelong']; $i ++) {
$pliststart .= '<a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '">' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
}
$pliststart .= ($cfg ['listsidelong'] + 1) == $pstart ? '' : $cfg ['more'] . ' ';
} else {
if ($cfg ['listsidelong'] >= $pstart && $pstart > 1) {
for($i = 1; $i <= ($pstart - 1); $i ++) {
$pliststart .= '<a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '">' . str_replace ( '*', $i, $cfg ['list'] ) . '</a> ';
}
}
}
if (($cfg ['pagecount'] - $cfg ['listsidelong']) > $pend) {
$plistend = ' ' . $cfg ['more'] . $plistend;
for($i = (($cfg ['pagecount'] - $cfg ['listsidelong']) + 1); $i <= $cfg ['pagecount']; $i ++) {
$plistend .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . ' </a> ';
}
} else {
if (($cfg ['pagecount'] - $cfg ['listsidelong']) <= $pend && $pend < $cfg ['pagecount']) {
for($i = ($pend + 1); $i <= $cfg ['pagecount']; $i ++) {
$plistend .= ' <a href="' . str_replace ( '*', $i, $cfg ['link'] ) . '"> ' . str_replace ( '*', $i, $cfg ['list'] ) . ' </a> ';
}
}
}
}
if ($cfg ['pageindex'] > 1) {
$pfirst = ' <a href="' . str_replace ( '*', '1', $cfg ['link'] ) . '">' . $cfg ['first'] . '</a> ';
$pprev = ' <a href="' . str_replace ( '*', $cfg ['pageindex'] - 1, $cfg ['link'] ) . '">' . $cfg ['prev'] . '</a> ';
} else {
$pfirst = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['first'] . '</span> ';
$pprev = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['prev'] . '</span> ';
}
if ($cfg ['pageindex'] < $cfg ['pagecount']) {
$plast = ' <a href="' . str_replace ( '*', $cfg ['pagecount'], $cfg ['link'] ) . '">' . $cfg ['last'] . '</a> ';
$pnext = ' <a href="' . str_replace ( '*', $cfg ['pageindex'] + 1, $cfg ['link'] ) . '">' . $cfg ['next'] . '</a> ';
} else {
$plast = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['last'] . '</span> ';
$pnext = ' <span class="' . $cfg ['disabledclass'] . '">' . $cfg ['next'] . '</span> ';
}
switch (strtolower ( $cfg ['jump'] )) {
case 'input' :
$pjumpvalue = 'this.value';
$pjump = '<input type="text" size="3" title="请输入要跳转到的页数并回车"' . (($cfg ['jumpplus'] == '') ? '' : ' ' . $cfg ['jumpplus']);
$pjump .= ' onkeydown="网页特效:if(event.charcode==13||event.keycode==13){if(!isnan(' . $pjumpvalue . ')){';
$pjump .= ($cfg ['jumpaction'] == '' ? ((strtolower ( substr ( $cfg ['link'], 0, 11 ) ) == 'javascript:') ? str_replace ( '*', $pjumpvalue, substr ( $cfg ['link'], 12 ) ) : " document.location.href='" . str_replace ( '*', ''+' . $pjumpvalue . '+'', $cfg ['link'] ) . '';') : str_replace ( "*", $pjumpvalue, $cfg ['jumpaction'] ));
$pjump .= '}return false;}" />';
break;
case 'select' :
$pjumpvalue = "this.options[this.selectedindex].value";
$pjump = '<select ' . ($cfg ['jumpplus'] == '' ? ' ' . $cfg ['jumpplus'] . ' onchange="javascript:' : $cfg ['jumpplus']);
$pjump .= ($cfg ['jumpaction'] == '' ? ((strtolower ( substr ( $cfg ['link'], 0, 11 ) ) == 'javascript:') ? str_replace ( '*', $pjumpvalue, substr ( $cfg ['link'], 12 ) ) : " document.location.href='" . str_replace ( '*', ''+' . $pjumpvalue . '+'', $cfg ['link'] ) . '';') : str_replace ( "*", $pjumpvalue, $cfg ['jumpaction'] ));
$pjump .= '" title="请选择要跳转到的页数"> ';
if ($cfg ['jumplong'] == 0) {
for($i = 0; $i <= $cfg ['pagecount']; $i ++) {
$pjump .= '<option value="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="selected"' : '') . ' >' . $i . '</option> ';
}
} else {
$pjumplong = intval ( $cfg ['jumplong'] / 2 );
$pjumpstart = ((($cfg ['pageindex'] - $pjumplong) < 1) ? 1 : ($cfg ['pageindex'] - $pjumplong));
$pjumpstart = ((($cfg ['pagecount'] - $cfg ['pageindex']) < $pjumplong) ? ($pjumpstart - ($pjumplong - ($cfg ['pagecount'] - $cfg ['pageindex'])) + 1) : $pjumpstart);
$pjumpstart = (($pjumpstart < 1) ? 1 : $pjumpstart);
$j = 1;
for($i = $pjumpstart; $i <= $cfg ['pageindex']; $i ++, $j ++) {
$pjump .= '<option value="' . $i . '"' . (($i == $cfg ['pageindex']) ? ' selected="selected"' : '') . '>' . $i . '</option> ';
}
$pjumplong = $cfg ['pagecount'] - $cfg ['pageindex'] < $pjumplong ? $pjumplong : $pjumplong + ($pjumplong - $j) + 1;
$pjumpend = $cfg ['pageindex'] + $pjumplong > $cfg ['pagecount'] ? $cfg ['pagecount'] : $cfg ['pageindex'] + $pjumplong;
for($i = $cfg ['pageindex'] + 1; $i <= $pjumpend; $i ++) {
$pjump .= '<option value="' . $i . '">' . $i . '</option> ';
}
}
$pjump .= '</select>';
break;
}
$patterns = array ('/{recordcount}/', '/{pagecount}/', '/{pageindex}/', '/{pagesize}/', '/{list}/', '/{liststart}/', '/{listend}/', '/{first}/', '/{prev}/', '/{next}/', '/{last}/', '/{jump}/' );
$replace = array ($cfg ['recordcount'], $cfg ['pagecount'], $cfg ['pageindex'], $cfg ['pagesize'], $plist, $pliststart, $plistend, $pfirst, $pprev, $pnext, $plast, $pjump );
$tmpstr = chr ( 13 ) . chr ( 10 ) . preg_replace ( $patterns, $replace, $tmpstr ) . chr ( 13 ) . chr ( 10 );
unset ( $cfg );
return $tmpstr;
}
}
?>
代码如下 | 复制代码 |
*/ $url = strtolower(trim($_get['url'])); $url = getshorturl($url); if (empty($pn)) $pn = 1; switch ($lm) { <body> function文件 <?php 源码下载地址 http://down.111cn.net/s/2010/1025/21415.html |
如果需要更新cookie以让其储存新值,只需要将其原值覆盖即可。因此,即使你已经在之前的页面中刚刚发送cookie,仍可以将你的名字改为"jeff"。
*/
代码如下 | 复制代码 |
$y2k = mktime(0,0,0,1,1,2000); setcookie('name', 'jeff', $y2k); |
/*
上面是个简单的cookie实例,下面我们来看个复杂的cookie 来作用户登录验证实例代码。
*/
代码如下 | 复制代码 |
function verify() function cookie($set = true) |
再有一种就是伪静态方式,即用户和搜索引擎看到的是.html后缀的静态页面,但实际上它还是动态程序,只不过是通过某种方式进行了伪装。
这种方式也有两种实现方式:
第一种是通过web服务器,进行url rewrite实现链接的静态化,下面以apache为例来说明一下其实现方式。对于有服务器配置权限的用户,推荐使用apache的mod_rewrite模块,这里假设已经安装好mod_rewrite模块。打开apache的配置文件,找到相应主机的部分,添加以下代码:
代码如下 | 复制代码 |
rewriteengine on rewriterule ^/abc/([a-z]+)/([0-9]+).html$ /abc.php?action=$1&id=$2 |
然后在shell里执行service httpd reload,让apache重新载入配置就好了。
但对于我们大多数人来讲,我们购买的只是空间,根本没有权限去修改apache的配置文件,那就没有办法了吗?不,当然有办法,首先我们进入到我们的空间的根目录下(如public_html),然后建立一个文件名为.htaccess的文件。这个文件内容基本如下:
代码如下 | 复制代码 |
rewriteengine on rewritebase / rewriterule ^post/([0-9]+).htm read.php?1 rewriterule ^post/([0-9]+)_([0-9]+).htm read.php?1&page=2 rewriterule ^post/([0-9]+)_([0-9]+)_([0-9]+).htm read.php?1&page=2&=3 |
php程序写法
代码如下 | 复制代码 |
function mod_rewrite(){ , 0 , strpos ( $_server [ ’ php_self ’ ] , ’ .php ’ ) + 4 ); . ’ ? ’ . $_server [ ’ query_string ’ ]; |
相关文章
- 下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
Jupyter Notebook读取csv文件出现的问题及解决
这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06- 有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
- 这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
- 这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
- C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
php无刷新利用iframe实现页面无刷新上传文件(1/2)
利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25- 本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
- 要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
- 又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
- 本文实例讲述了jQuery实现文件上传进度条效果的代码。分享给大家供大家参考。具体如下: 运行效果截图如下:具体代码如下:<!DOCTYPE html><html><head><meta charset="utf-8"><title>upload</title><link rel="stylesheet...2015-11-24
- 步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
- 今天小编在这里就来给photoshop的这一款软件的使用者们来说下AI源文件转photoshop图像变模糊问题的解决教程,各位想知道具体解决方法的使用者们,那么下面就快来跟着小编...2016-09-14
- 这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
- 本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
ant design中upload组件上传大文件,显示进度条进度的实例
这篇文章主要介绍了ant design中upload组件上传大文件,显示进度条进度的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-29- 这篇文章主要介绍了C#使用StreamWriter写入文件的方法,涉及C#中StreamWriter类操作文件的相关技巧,需要的朋友可以参考下...2020-06-25
- 举一个案例:复制代码 代码如下:<?phpclass Downfile { function downserver($file_name){$file_path = "./img/".$file_name;//转码,文件名转为gb2312解决中文乱码$file_name = iconv("utf-8","gb2312",$file_name...2014-06-07
- 这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25