Home  >  Article  >  Backend Development  >  php上传原理与实例

php上传原理与实例

WBOY
WBOYOriginal
2016-06-23 13:30:06881browse

1.form标签enctype属性

2.$_FILES系统函数

$_FILES['myFile']['name']客户端文件的原名称

$_FILES['myFile']['type']文件的MIME类型,例如"image/gif".

$_FILES['myFile']['size']已上传文件的大小,单位为字节

$_FILES['myFile']['tmp_name']储存的临时文件名,一般时系统默认的

$_FILES['myFile']['error']该文件上传相关的错误编码

 

0:表示文件上传成功

1.超过文件的大小 php.ini中

2.超过文件大小max_file_size指定的值

3.文件只有不发呢被上传

4没有文件被上传

5上传文件大小为0

3.move_uploaaded_file函数

    上传后移动文件到目标位置的函数

move_uploaded_file(临时文件,目标位置和文件名);

4.is_uploaded_file函数

      判断上传mime类型的文件函数

move_uploaded_file(MIME);

 

实例:

1.

if(is_uploaded_file($_FILES['upfile']['tmp_name'])){

$upfiles=$_FILES["upfile"];

}

$name=$upfile["name"];

$type=$upfiles["type"];

$size=$upfiles["size"];

$tmp_name=$upfile["tmp_name"];

switch($type){

case 'image/pjpeg';

   break;

case 'image/jpeg';

   break;

case 'image/gif';

   break;

case 'image/png';

   break;

}

if(move_uploaded_file($tmp_name,'up/'.$name))

{ echo "上传成功"}

}

?>

上传文件:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn