Home > Backend Development > PHP Tutorial > PHP file upload simple example sharing

PHP file upload simple example sharing

小云云
Release: 2023-03-20 13:32:01
Original
1565 people have browsed it

This article mainly shares with you a simple example of php file upload, hoping to help everyone.

##文件上传
1.在表单头要写入enctype="multipart/form-data";
2.最好定义一个隐藏的hidden,name="MAX_FILE_SIZE"value来定义大小
##使用到的函数
1.is_uploaded_file用来判定文件是否是通过HTTP-HOST上传的,返回bool值
2.move_uploaded_file('临时文件路径','目标文件路径')
其中临时文件路径是指$_FILES[pic][tmp_name]当中的值
##处理多个文件上传是,post所传的的数组信息
是$_FILES[pic][tmp_name][0]这个元素这是第一个文件的临时存储路径
是$_FILES[pic][name][0]这个元素这是第一个文件的文件名
是$_FILES[pic][error][0]这个元素这是第一个文件的出错信息
是$_FILES[pic][size][0]这个元素这是第一个文件的大小
以此类推,第二个文件下标就增加,几个文件下标就依次增加。也就是说原来的存放元素的位置全部变成了一个数组,用来存放其他组的相同信息
##文件下载
只需要一个普通的a链接就可以定义一个下载路径
但是不能识别MIME类型的文件,会直接打开而不是显示下载,所以我们要让a链接跳转到操作页面对头部信息进行设置
header('Contebt-Type:image/gif');//发送指定类型的头信息
header('Content-Disposition:attachment;filename;filename="test.gif"');//发送文件的头信息,文件名和附件名
header('Content-Lenght:3390');//发送指定文件大小
Copy after login

Related recommendations:

What should be paid attention to when uploading php files

##php file upload class and PHP encapsulated multi-file upload class sharing

PHP file upload analysis

The above is the detailed content of PHP file upload simple example sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template