博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php文件上传 覆盖上传_使用PHP上传基本文件
阅读量:2512 次
发布时间:2019-05-11

本文共 2882 字,大约阅读时间需要 9 分钟。

php文件上传 覆盖上传

I create a lot of websites that allow administrators to upload files to their own website. Since allowing user customization has become more and more important on websites these days, I thought I'd share how easy it is to handle file uploads in PHP.

我创建了许多网站,允许管理员将文件上传到自己的网站。 由于近来允许用户自定义在网站上变得越来越重要,所以我想分享一下使用PHP处理文件上传的难易程度。

XHTML表单 (The XHTML Form)

Your Photo:

You'll need to use the multipart/form-data value for the form's enctype property. You'll also obviously need at least one input element of the file type. The form's action tag must provide a URL which points the a file containing the piece of PHP below.

您需要将multipart / form-data值用于表单的enctype属性。 显然,您还至少需要一个文件类型的输入元素。 表单的动作标签必须提供一个URL,该URL指向一个包含下面PHP片段的文件。

PHP (The PHP)

//if they DID upload a file...if($_FILES['photo']['name']){	//if no errors...	if(!$_FILES['photo']['error'])	{		//now is the time to modify the future file name and validate the file		$new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file		if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB		{			$valid_file = false;			$message = 'Oops!  Your file\'s size is to large.';		}				//if the file has passed the test		if($valid_file)		{			//move it to where we want it to be			move_uploaded_file($_FILES['photo']['tmp_name'], 'uploads/'.$new_file_name);			$message = 'Congratulations!  Your file was accepted.';		}	}	//if there is an error...	else	{		//set that to be the returned message		$message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error'];	}}//you get the following information for each file:$_FILES['field_name']['name']$_FILES['field_name']['size']$_FILES['field_name']['type']$_FILES['field_name']['tmp_name']

My commenting in the PHP above outlines the way the process works, so I'll just mention a few notes about file uploads in PHP:

我在上面PHP中的评论概述了该过程的工作方式,因此,我仅提及有关PHP中文件上传的一些注意事项:

  • Many shared hosting servers allow a very low maximum file upload size. If you plan on accepting larger files, you should consider a dedicated or virtual dedicated server.

    许多共享的托管服务器允许非常小的最大文件上传大小。 如果计划接受较大的文件,则应考虑使用专用服务器或虚拟专用服务器。
  • To adjust the file upload size in PHP, modify the php.ini file's "upload_max_filesize" value. You can also adjust this value using PHP's .ini_set() function.

    要在PHP中调整文件上传大小,请修改php.ini文件的“ upload_max_filesize”值。 您还可以使用PHP的.ini_set()函数来调整此值。

  • The file upload counts towards the hosting environment's $_POST size, so you may need to increase the php.ini file's post_max_size value.

    文件上载将计入托管环境的$ _POST大小,因此您可能需要增加php.ini文件的post_max_size值。

  • Be sure to do a lot of file validation when allowing users to upload files. How horrible would it be to allow a user to upload a .exe file to your server? They could do horrible things on the server.

    允许用户上传文件时,请确保进行大量文件验证。 允许用户将.exe文件上传到您的服务器有多可怕? 他们可能在服务器上做可怕的事情。

翻译自:

php文件上传 覆盖上传

转载地址:http://nupwd.baihongyu.com/

你可能感兴趣的文章
btn按钮之间事件相互调用
查看>>
Entity Framework 4.3.1 级联删除
查看>>
codevs 1163:访问艺术馆
查看>>
冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
查看>>
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
学习进度
查看>>
“此人不存在”
查看>>
github.com加速节点
查看>>
解密zend-PHP凤凰源码程序
查看>>
python3 序列分片记录
查看>>
Atitit.git的存储结构and 追踪
查看>>
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>