PHP文件上传小程序 适合初学者学习_第1页
PHP文件上传小程序 适合初学者学习_第2页
PHP文件上传小程序 适合初学者学习_第3页
PHP文件上传小程序 适合初学者学习_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第PHP文件上传小程序适合初学者学习!本文实例为大家分享了PHP文件上传小程序的具体代码,供大家参考,具体内容如下

废话略过,直接上代码:

首先前端代码:index.html

html

head

metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"

title文件上传Demo/title

/head

body

formmethod="post"action="upload.php"enctype="multipart/form-data"

tableborder=0cellspacing=0cellpadding=0align=centerwidth="100%"

tdwidth=55height=20align="center"

inputtype="hidden"name="MAX_FILE_SIZE"value="2000000"文件:

/td

tdheight="16"

inputname="file"type="file"value="浏览"/

inputtype="submit"value="上传"name="submit"/

/td

/tr

/table

/form

/body

/html

接下来是重点:upload.php

*@title文件上传示例

*@authorFeoniX

header("Content-Type:text/html;charset=utf-8");

if($_POST['submit']){

$upfiles=newUpload();

$upfiles-upload_file();

classUpload{

public$upload_name;//上传文件名

public$upload_tmp_name;//上传临时文件名

public$upload_final_name;//上传文件的最终文件名

public$upload_target_dir;//文件被上传到的目标目录

public$upload_target_path;//文件被上传到的最终路径

public$upload_filetype;//上传文件类型

public$allow_uploadedfile_type;//允许的上传文件类型

public$upload_file_size;//上传文件的大小

public$allow_uploaded_maxsize=10000000;//允许上传文件的最大值

//构造函数

publicfunction__construct()

$this-upload_name=$_FILES["file"]["name"];//取得上传文件名

$this-upload_filetype=$_FILES["file"]["type"];

$this-upload_tmp_name=$_FILES["file"]["tmp_name"];

$this-allow_uploadedfile_type=array('jpeg','jpg','png','gif','bmp','doc','xls','csv','zip','rar','txt','wps');

$this-upload_file_size=$_FILES["file"]["size"];

$this-upload_target_dir="./upload";

//文件上传

publicfunctionupload_file()

$upload_filetype=$this-getFileExt($this-upload_name);//获取文件扩展名

if(in_array($upload_filetype,$this-allow_uploadedfile_type))//判断文件类型是否符合要求

if($this-upload_file_size$this-allow_uploaded_maxsize)//判断文件大小是否超过允许的最大值

if(!is_dir($this-upload_target_dir))//如果文件上传目录不存在

mkdir($this-upload_target_dir);//创建文件上传目录

chmod($this-upload_target_dir,0777);//改权限

$this-upload_final_name=date("YmdHis").rand(0,100).'.'.$upload_filetype;//生成随机文件名

$this-upload_target_path=$this-upload_target_dir."/".$this-upload_final_name;//文件上传目标目录

if(!move_uploaded_file($this-upload_tmp_name,$this-upload_target_path))//文件移动失败

echo"fontcolor=red文件上传失败!/font

else

echo"fontcolor=green文件上传成功!/font

else

echo("fontcolor=red文件太大,上传失败!/font

else

echo("fontcolor=red仅支持一下文件类型,请重新选择:br".implode(',',$this-allow_uploadedfile_type)."/font

*获取文件扩展名

*@paramString$filename要获取文件名的文件

publi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论