首页 > 编程技术 > php

文件上传错误信息说明

发布时间:2016-11-25 15:17

错误信息说明从 PHP 4.2.0 开始,

PHP 将随文件信息数组一起返回一个对应的错误代码。该代码可以在文件上传时生成的文件数组中的 error 字段中被找到,

也就是 $_FILES["userfile"]["error"]。

UPLOAD_ERR_OK 其值为 0,没有错误发生,文件上传成功。
UPLOAD_ERR_INI_SIZE 其值为 1,上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。
UPLOAD_ERR_FORM_SIZE 其值为 2,上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。
UPLOAD_ERR_PARTIAL 其值为 3,文件只有部分被上传。
UPLOAD_ERR_NO_FILE 其值为 4,没有文件被上传。
UPLOAD_ERR_NO_TMP_DIR 其值为 6,找不到临时文件夹。PHP 4.3.10 和 PHP 5.0.3 引进。
UPLOAD_ERR_CANT_WRITE 其值为 7,文件写入失败。PHP 5.1.0 引进。

<?
/*    中文处理工具函数
--- 空格 ---
      string GBspace(string) --------- 每个中文字之间加空格
      string GBunspace(string) ------- 每个中文字之间的空格清除
      string clear_space(string) ------- 用来清除多余的空格

--- 转换 ---
      string GBcase(string,offset) --- 将字符串内的中英文字转换大小写
                              offset : "upper"   - 字符串全转为大写 (strtoupper)
                                       "lower"   - 字符串全转为小写 (strtolower)
                                       "ucwords" - 将字符串每个字第一个字母改大写 (ucwords)
                                       "ucfirst" - 将字符串第一个字母改大写 (ucfirst)
      string GBrev(string) ----------- 颠倒字符串

--- 文字检查 ---
      int GB_check(string) ----------- 检查字符串内是否有 GB 字,有会返回 true,
                                         否则会返回false
      int GB_all(string) ------------- 检查字符串内所有字是否有 GB 字,是会返回 true,
                                         否则会返回false
      int GB_non(string) ------------- 检查字符串内所有字并不是 GB 字,是会返回 true,
                                         否则会返回false
      int GBlen(string) -------------- 返回字符串长度(中文字只计一字母)

--- 查找、取代、提取 ---
      int/array GBpos(haystack,needle,[offset]) ---- 查找字符串 (strpos)
                              offset : 留空 - 查找第一个出现的位置
                                       int  - 由该位置搜索出现的第一个位置
                                       "r"  - 查找最后一次出现的位置 (strrpos)
                                       "a"  - 将所有查找到的字储存为数组(返回 array)

      string GB_replace(needle,str,haystack) -- 查找与取代字符串 (str_replace)
      string GB_replace_i(needle,str_f,str_b,haystack) -- 不检查大小写查找与取代字符串
                                         needle - 查找字母
                                         str - 取代字母 ( str_f - 该字母前, str_b 该字母后)
                                         haystack - 字符串

      string GBsubstr(string,start,[length]) -- 从string提取出由开始到结尾或长度
                                                  length的字符串。
                                                  中文字只计一字母,可使用正负数。
      string GBstrnear(string,length)         -- 从 string提取最接近 length的字符串。
                                                   length 中 中文字计2个字母。

--- 注意 ---
      如使用由 Form 返回的字符串前,请先替字符串经过 stripslashes() 处理,除去多余的 \ 。

      用法:在原 PHP 代码内加上:
      include ("GB.inc");
      即可使用以上工具函数。
*/

function GBlen($string) {
    $l = strlen($string);
    $ptr = 0;
    $a = 0;
    while ($a < $l) {
        $ch = substr($string,$a,1);
        $ch2 = substr($string,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
            $ptr++;
            $a += 2;
        } else {
            $ptr++;
            $a++;
        } // END IF
    } // END WHILE

    return $ptr;
}

function GBsubstr($string,$start,$length) {
    if (!is_int($length) && $length != "") {
        return "错误:length 值错误(必须为数值)。<br>";
    } elseif ($length == "0") {
        return "";
    } else {
    $l = strlen($string);
    $a = 0;
    $ptr = 0;
    $str_list = array();
    $str_list2 = array();
    while ($a < $l) {
        $ch = substr($string,$a,1);
        $ch2 = substr($string,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
            $str_list[$ptr] = $a;
            $str_list2[$ptr] = $a+1;
            $ptr++;
            $a += 2;
        } else {
            $str_list[$ptr] = $a;
            $str_list2[$ptr] = $a;
            $ptr++;
            $a++;
        } // END IF
    } // END WHILE

    if ($start > $ptr || -$start > $ptr) {
        return;
    } elseif ($length == "") {
        if ($start >= 0) { // (text,+)
            return substr($string,$str_list[$start]);
        } else { // (test,-)
            return substr($string,$str_list[$ptr + $start]);
        }
    } else {

        if ($length > 0) { // $length > 0


            if ($start >= 0) {  // (text,+,+)
                if (($start + $length) >= count($str_list2)) {
                    return substr($string,$str_list[$start]);
                } else { //(text,+,+)
                    $end = $str_list2[$start + ($length - 1)] - $str_list[$start] +1;
                    return substr($string,$str_list[$start],$end);
                }

            } else { // (text ,-,+)
                $start = $ptr + $start;
                if (($start + $length) >= count($str_list2)) {
                    return substr($string,$str_list[$start]);
                } else {
                    $end = $str_list2[$start + ($length - 1)] - $str_list[$start] +1;
                    return substr($string,$str_list[$start],$end);
                }
            }

        } else { // $length < 0
            $end = strlen($string) - $str_list[$ptr+$length];
            if ($start >= 0) {  // (text,+,-) {
                return substr($string,$str_list[$start],-$end);
            } else { //(text,-,-)
                $start = $ptr + $start;
                return substr($string,$str_list[$start],-$end);
            }

        } // END OF LENGTH > / < 0

    }
    } // END IF
}

function GB_replace($needle,$string,$haystack) {
    $l = strlen($haystack);
    $l2 = strlen($needle);
    $l3 = strlen($string);
    $news = "";
    $skip = 0;
    $a = 0;
    while ($a < $l) {
        $ch = substr($haystack,$a,1);
        $ch2 = substr($haystack,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
            if (substr($haystack,$a,$l2) == $needle) {
                $news .= $string;
                $a += $l2;
            } else {
                $news .= $ch.$ch2;
                $a += 2;
            }
        } else {
            if (substr($haystack,$a,$l2) == $needle) {
                $news .= $string;
                $a += $l2;
            } else {
                $news .= $ch;
                $a++;
            }
        } // END IF
    } // END WHILE
    return $news;
}

function GB_replace_i($needle,$str_f,$str_b,$haystack) {

    $l = strlen($haystack);
    $l2 = strlen($needle);
    $l3 = strlen($string);
    $news = "";
    $skip = 0;
    $a = 0;
    while ($a < $l) {
        $ch = substr($haystack,$a,1);
        $ch2 = substr($haystack,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
            if (GBcase(substr($haystack,$a,$l2),"lower") == GBcase($needle,"lower")) {
                $news .= $str_f . substr($haystack,$a,$l2) . $str_b;
                $a += $l2;
            } else {
                $news .= $ch.$ch2;
                $a += 2;
            }
        } else {
            if (GBcase(substr($haystack,$a,$l2),"lower") == GBcase($needle,"lower")) {
                $news .= $str_f . substr($haystack,$a,$l2) . $str_b;
                $a += $l2;
            } else {
                $news .= $ch;
                $a++;
            }
        } // END IF
    } // END WHILE
    return $news;
}



function GBpos($haystack,$needle,$offset) {
    if (!is_int($offset)) {
        $offset = strtolower($offset);
        if ($offset != "" && $offset != "r" && $offset != "a") {
            return "错误:offset 值错误。<br>";
        }
    }
    $l = strlen($haystack);
    $l2 = strlen($needle);
    $found = false;
    $w = 0; // WORD
    $a = 0; // START

    if ($offset == "" || $offset == "r") {
        $atleast = 0;
        $value = false;
    } elseif ($offset == "a") {
        $value = array();
        $atleast = 0;
    } else {
        $value = false;
        $atleast = $offset;
    }
    while ($a < $l) {
        $ch = substr($haystack,$a,1);
        $ch2 = substr($haystack,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40") && $skip == 0) {
            if (substr($haystack,$a,$l2) == $needle) {
                if ($offset == "r") {
                    $found = true;
                    $value = $w;
                } elseif ($offset == "a") {
                    $found = true;
                    $value[] = $w;
                } elseif (!$value) {
                    if ($w >= $atleast) {
                        $found = true;
                        $value = $w;
                    }
                }
            }
            $a += 2;
        } else {
            if (substr($haystack,$a,$l2) == $needle) {
                if ($offset == "r") {
                    $found = true;
                    $value = $w;
                } elseif ($offset == "a") {
                    $found = true;
                    $value[] = $w;
                } elseif (!$value) {
                    if ($w >= $atleast) {
                        $found = true;
                        $value = $w;
                    }
                }
            }
            $a++;
        }
        $w++;
    } // END OF WHILE
    if ($found) {
        return $value;
    } else {
        return $false;
    }
//    } // END OF WHILE

}

function GBrev($text) {
    $news = "";
    $l = strlen($text);
    $GB = 0;
    $a = 0;
    while ($a < $l) {
        $ch = substr($text,$a,1);
        $ch2 = substr($text,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40") && $skip == 0) {
            $a += 2;
            $news = $ch . $ch2 . $news;
        } else {
            $news = $ch . $news;
            $a++;
        }
    }
    return $news;
}

function GB_check($text) {
    $l = strlen($text);
    $a = 0;
    while ($a < $l) {
        $ch = substr($text,$a,1);
        $ch2 = substr($text,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
            return true;
        } else {
            return false;
        }
    }
}

function GB_all ($text) {
    $l = strlen($text);
    $all = 1;
    $a = 0;
    while ($a < $l) {
        $ch = substr($text,$a,1);
        $ch2 = substr($text,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
            $a += 2;
        } else {
            $a++;
            $all = 0;
        }
    }
    if ($all == 1) {
        return true;
    } else {
        return false;
    }
}

function GB_non ($text) {
    $l = strlen($text);
    $all = 1;
    $a = 0;
    while ($a < $l) {
        $ch = substr($text,$a,1);
        $ch2 = substr($text,$a+1,1);
        if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
            $a += 2;
            $all = 0;
        } else {
            $a++;
        }
    }
    if ($all == 1) {
        return true;
    } else {
        return false;
    }
}


function GBcase ($text,$case) {
    $case = strtolower($case);
    if ($case != "upper" && $case != "lower" && $case != "ucwords" && $case != "ucfirst") {
        return "函数用法错误。 $case";
    } else {
    $ucfirst = 0;
    $ucwords = 0;
    $news = "";
    $l = strlen($text);
    $GB = 0;
    $english = 0;

    $a = 0;
    while ($a < $l) {

    $ch = substr($text,$a,1);
    if ($GB == 0 && ord($ch) >= HexDec("0x81")) {

            $GB = 1;
            $english = 0;
            $news .= $ch;
            $ucwords = 0;
    
    } elseif ($GB == 1 && ord($ch) >= HexDec("0x40") && $english == 0) {
            $news .= "$ch";    
            $ucwords = 0;
            $GB = 0;

    } else {
        if ($case == "upper") {
            $news .= strtoupper($ch);
        } elseif ($case == "lower") {
            $news .= strtolower($ch);
        } elseif ($case == "ucwords") {
            if ($ucwords == 0) {
                $news .= strtoupper($ch);
            } else {
                $news .= strtolower($ch);
            }
            $ucwords = 1;
        } elseif ($case == "ucfirst") {
            if ($ucfirst == 0) {
                $news .= strtoupper($ch);
                $ucfirst = 1;
            } else {
                $news .= strtolower($ch);
                $ucfirst = 1;
            }
        } else {
            $news .= $ch;
        }
        if ($ch == " " || $ch == "\n") {
            $ucwords = 0;
        }
        $english = 1;
        $GB = 0;
    
    }

    $a++;
    
    } // END OF while
    return $news;
    } // end else
}



function GBspace ($text) {

    $news = "";
    $l = strlen($text);
    $GB = 0;
    $english = 0;

    $a = 0;
    while ($a < $l) {


    $ch = substr($text,$a,1);
    $ch2 = substr($text,$a+1,1);
    if (!($ch == " " && $ch2 == " ")) {
    if ($GB == 0) {
        if (ord($ch) >= HexDec("0x81")) {

            if ($english == 1) {
                if ((substr($text,$a-1,1) == " ") || (substr($text,$a-1,1) == "\n")) {
                    $news .= "$ch";
                } else {
                    $news .= " $ch";
                }
                $english = 0;
                $GB = 1;
            } else {
                $GB = 1;
                $english = 0;
                $news .= $ch;
            }
        } else {
            $english = 1;
            $GB = 0;
            $news .= $ch;
        }
        
    } else {
        if (ord($ch) >= HexDec("0x40")) {
            if ($english == 0) {
                if ((substr($text,$a+1,1) == " ")|| (substr($text,$a+1,1) == "\n")) {
                    $news .= "$ch";    
                } else {
                    $news .= "$ch ";
                }
            } else {
                $news .= " $ch";
            }
        } else {
            $english = 1;
            $news .= "$ch";
        }
        $GB = 0;
    }
    }
    $a++;
    } // END OF while

    // Chk 1 & last is space

    $l = strlen($news);
    if (substr($news,0,1) == " ") {
        $news = substr($news,1);
    }
    $l = strlen($news);
    if (substr($news,$l-1,1) == " ") {
        $news = substr($news,0,$l-1);
    }
    return $news;
}

function GBunspace($text) {
    $news = "";
    $l = strlen($text);
    $a = 0;
    $last_space = 1;
    while ($a < $l) {
    
        $ch = substr($text,$a,1);
        $ch2 = substr($text,$a+1,1);
        $ch3 = substr($text,$a+2,1);
        if (($a + 1) == $l ) {
            $last_space = 1;
        }
        if ($ch == " ") {
            if ($last_space == 0) {
            if (ord($ch2) >= HexDec("0x81") && ord($ch3) >= HexDec("0x40")) {
                if ($chi == 0) {
                    $news .= " ";
                    $last_space = 1;
                }
                $chi=1;


            } elseif ($ch2 != " ") {
                $news .= " ";
                $chi = 0;
                $last_space = 1;
            }
            }
        } else {
            if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
                $chi = 1;
                $a++;
                $news .= $ch . $ch2;
                $last_space = 0;

            } else {
                $chi = 0;
                $news .= $ch;
                $last_space = 0;
            }

        }
    $a++;
    }
    // Chk 1 & last is space

    $l = strlen($news);
    if (substr($news,0,1) == " ") {
        $news = substr($news,1);
    }
    $l = strlen($news);
    if (substr($news,$l-1,1) == " ") {
        $news = substr($news,0,$l-1);
    }
    return $news;



} // END OF Function

function GBstrnear($text,$length) {

$tex_len = strlen($text);
$a = 0;
$w = "";
while ($a < $tex_len) {
        $ch = substr($text,$a,1);
        $ch2 = substr($text,$a+1,1);
        if (GB_all($ch.$ch2)) {
            $w .= $ch.$ch2;
            $a=$a+2;
        } else {
            $w .= $ch;
            $a++;
        }
        if ($a == $length || $a == ($length - 1)) {
            $a = $tex_len;
        }
}
return $w;
} // END OF FUNCTION

function clear_space($text) {
    $t = "";
    for ($a=0;$a<strlen($text);$a++) {
        $ch = substr($text,$a,1);
        $ch2 = substr($text,$a+1,1);
        if ($ch == " " && $ch2 == " ") {
        } else {
            $t .= $ch;
        }
    }
    return $t;
}


?>

首先删除不必要的文件节省空间。凡是以_开头的文件如_samples,_testcases和一些用不到的.asp、.jsp、.cfm文件统统干掉。

2修改fckconfig.js
FCKConfig.AutoDetectLanguage = true ;//是否自动检测语言
FCKConfig.DefaultLanguage  = 'zh-cn' ;//设置语言
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ;//设置皮肤
FCKConfig.TabSpaces = 1 ;//tab是否有效
FCKConfig.ToolbarStartExpanded = true ;//编辑工具条是否出现,等点“展开工具栏”时才出现
FCKConfig.FontNames  = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;//添加中文字体

修改FCKeditor\editor\css\fck_editorarea.css
设置默认字体及大小
body, td
{
font-family: Arial, Verdana, Sans-Serif;
font-size: 14px;
}

3关于文件上传的设置

修改fckconfig.js
var _FileBrowserLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php
var _QuickUploadLanguage = 'php' ; // asp | aspx | cfm | lasso | php

修改fckeditor\editor\filemanager\browser\default\connectors\php
$Config['Enabled'] = true ;
$Config['UserFilesPath'] = '/UserFiles/' ;//设置上传的文件夹,可自己指定

修改fckeditor\editor\filemanager\upload\php
$Config['Enabled'] = true ;
$Config['UseFileType'] = true ;
$Config['UserFilesPath'] = '/UserFiles/' ;//同上要一样

4引入在线编辑器时只需
<?php
include("fckeditor/fckeditor.php") ;
$oFCKeditor = new FCKeditor('FCKeditor1') ;//实例化
$oFCKeditor->BasePath = 'fckeditor/';//这个路径一定要和上面那个引入路径一致,否则会报错:找不到fckeditor.html页面
//$oFCKeditor->Value = '' ;默认值
$oFCKeditor->Width = '100%' ; //宽度
$oFCKeditor->Height = '300' ; //fck
$oFCKeditor->Create() ;
?>
========================
取得数据
$sValue = addslashes( $_POST['FCKeditor1'] ) ;

显示数据stripslashes,原因是addslashes函数加'加上了\'而stripslashes取还原由addslashes处理的数.

foreach()有两种用法
1: foreach(array as $value)
   { 
      表达式;
   }
这里的array是你要遍历的数组名,每次循环中,array数组的当前元素的值被赋给$value,

并且数组内部的下标向下移一步,也就是下次循环回得到下一个元素

2:foreach(array_name as $key => $value)
   {
       表达式   

  }  

这里跟第一种方法的区别就是多了个$key,也就是除了把当前元素的值赋给$value外,当前元素的键值也会在每次循环中被赋给变量$key。键值可以是下标值,也可以是字符串。比如book[0]=1中的“0”,book[id]="001"中的“id”.

其实两种的效率不相上下.

教你如何 配置 phpMyAdmin

下载:请到phpmyadmin官方站点 http://www.phpmyadmin.net/ 下载phpmyadmin文件,

解压后对phpmyadmin进行设置我边讲例子别解析:

解压后得到一个目录,与以前的版本不同,2.8版的phpMyAdmin 的根目录中没有名为 config.inc.php 的配置文件,现在的配置文件是 libraries/config.default.php 进在该文件中

我的目录为:http://www.111cn.net/myadmin/


找到 $cfg['PmaAbsoluteUri']
修改你将上传到空间的phpMyAdmin的网址
如:$cfg['PmaAbsoluteUri'] = 'http://yoursite/phpmyadmin/';

还有下面的
$cfg['Servers'][$i]['host'] = 'localhost';(通常用默认, 也可能是主机IP)


$cfg['Servers'][$i]['host'] = 'localhost;这里是默认的我们一般不改

$cfg['Servers'][$i]['auth_type'] = 'cookie';

$cfg['Servers'][$i]['user'] = 'root';

$cfg['Servers'][$i]['password'] = '******';

为了安全起见我们找到设置$cfg['Servers'][$i]['auth_type'] = ''修改值勤cookie


$cfg['Servers'][$i]['auth_type'] = 'cookie'; // Authentication method (config, http or cookie based)?
config: 按照 自身 libraries/config.default.php 文件中的配置提供用户名和密码
cookie:用于输入口令方式登陆,如果选择此项,需要设置$cfg['blowfish_secret'] = 'cookie';(见后面的介绍)

$cfg['Servers'][$i]['user'] = 'root'; // MySQL user(用户名,自己机里用root,在网上设你的mysql用户名)
$cfg['Servers'][$i]['password'] = ''; // MySQL password (only needed
自己机里不用设
$cfg['Servers'][$i]['only_db'] = ''; // If set to a db-name, only(你只有一个数据就设置一下)

注:$cfg['blowfish_secret'] = '';
本机的话不需要设置,但是网络的话需要设置成cookie:
$cfg['blowfish_secret'] = 'cookie';

设置完毕可以上传到网上了。

浏览http://yoursite//phpmyadmin/ 当然你设置不同就用那个网址。
如果设置$cfg['Servers'][$i]['auth_type'] = 'cookie'; 所以显示会要求输入帐号密码,这里的帐号和密码你在提供商获得的mysql数据库的帐号、密码。

好了,就这么简单,对新手应该有一点点帮助.

标签:[!--infotagslink--]

您可能感兴趣的文章: