search
Homephp教程PHP源码php 简单清析文件上传

<script>ec(2);</script>

function Uploadfile(){
   //文件保存目录路径
   $save_path = '../upload/';
   //定义允许上传的文件扩展名
   $ext_arr = array('rar','zip');
   //最大文件大小
   $max_size = 1000000;
   //更改目录权限
   @mkdir($save_path, 0777);
   
   
   //有上传文件时
   if (empty($_FILES) === false) {
    //原文件名
    $file_name = $_FILES['fileData']['name'];
    //服务器上临时文件名
    $tmp_name = $_FILES['fileData']['tmp_name'];
    //文件大小
    $file_size = $_FILES['fileData']['size'];
    //检查目录
    if (@is_dir($save_path) === false) {
     alert("上传目录不存在。");
    }
    //检查目录写权限
    if (@is_writable($save_path) === false) {
     alert("上传目录没有写权限。");
    }
    //检查是否已上传
    if (@is_uploaded_file($tmp_name) === false) {
     alert("临时文件可能不是上传文件。");
    }
    //检查文件大小
    if ($file_size > $max_size) {
     alert("上传文件大小超过限制。");
    }
    //获得文件扩展名
    $temp_arr = explode(".", $file_name);
    $file_ext = array_pop($temp_arr);
    $file_ext = trim($file_ext);
    $file_ext = strtolower($file_ext);
    //检查扩展名
    if (in_array($file_ext, $ext_arr) === false) {
     alert("上传文件扩展名是不允许的扩展名。");
    }
    //移动文件
    if (move_uploaded_file($tmp_name, $file_path) === false) {
     alert("上传文件失败。");
    }
 } 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.