php文件上传类 php文件上传代码
一个简单的php文件上传的类,在整理 php 类时发现的一个图片处理类,PHP 处理图片的类已经很多了,有单独处理图片的,也有加水印的,也有生成图片的,总之,在 PHP 当中,处理图片已经很简单了,甚至在一些小型的应用中,直接应用 PHP 的面向过程就可以实现图片的上传过程,当然,为了程序的规范,我们还是有必要使用PHP的面向对象的
下面的这个PHP文件的上传类主要是用来上传文件的,包括图片,视频,word文档的,其实这里建议用来处理图片,推荐的主要原因是这个类很规范,基本上所有的上传参数都可以在类里面进行定义,而不需要在 php.ini 里面进行修改
代码如下 | 复制代码 |
class files{ //文件保存目录路径 $save_path = realpath($save_path) . '/'; //有上传文件时 $dbsave = ""; //数据库中存放的路径 if ($dir_name !== '') { $y = date("Y"); $save_path .= $y . "/"; $save_path .= $m . "/"; $save_path .= $d . "/"; //新文件名 if (move_uploaded_file($tmp_name, $file_path) === false) { |
通过使用 PHP 的全局数组 $_FILES,你可以从客户计算机向远程服务器上传文件。
第一个参数是表单的 input name,第二个下标可以是 "name", "type", "size", "tmp_name" 或 "error"。就像这样:
•$_FILES["file"]["name"] - 被上传文件的名称
•$_FILES["file"]["type"] - 被上传文件的类型
•$_FILES["file"]["size"] - 被上传文件的大小,以字节计
•$_FILES["file"]["tmp_name"] - 存储在服务器的文件的临时副本的名称
•$_FILES["file"]["error"] - 由文件上传导致的错误代码
这是一种非常简单文件上传方式。基于安全方面的考虑,您应当增加有关什么用户有权上传文件的限制。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
