search
Homephp教程php手册php实现文件上传的源码,

php实现文件上传的源码,

Jun 13, 2016 am 09:21 AM
httpphpuploadaccomplishtechnology developmentTutorialdocumentSource codeofnet

php实现文件上传的源码,

php实现文件上传的源码,更多php技术开发就去php教程网,http://php.662p.com

<?php
        ##author :Androidyue
        ##sina @androidyue
        ##Blog http://blog.csdn.net/BossDarcy
        ##源码具体讲解  http://blog.csdn.net/BossDarcy/archive/2010/12/20/6086082.aspx
        //判断临时文件存放路径是否包含用户上传的文件
        if(is_uploaded_file($_FILES["uploadfile"]["tmp_name"])){
        //为了更高效,将信息存放在变量中
        $upfile=$_FILES["uploadfile"];//用一个数组类型的字符串存放上传文件的信息
        //print_r($upfile);//如果打印则输出类似这样的信息Array ( [name] => m.jpg [type] => image/jpeg [tmp_name] => C:\WINDOWS\Temp\php1A.tmp [error] => 0 [size] => 44905 )
        $name=$upfile["name"];//便于以后转移文件时命名
        $type=$upfile["type"];//上传文件的类型
        $size=$upfile["size"];//上传文件的大小
        $tmp_name=$upfile["tmp_name"];//用户上传文件的临时名称
        $error=$upfile["error"];//上传过程中的错误信息
        //echo $name;
        //对文件类型进行判断,判断是否要转移文件,如果符合要求则设置$ok=1即可以转移
        switch($type){
            case "image/jpg": $ok=1;
            break;
            case "image/jpeg": $ok=1;
            break;
            case "image/gif" : $ok=1;
            break;
            default:$ok=0;
            break;
        }
        //如果文件符合要求并且上传过程中没有错误
        if($ok&&$error=='0'){
            //调用move_uploaded_file()函数,进行文件转移
            move_uploaded_file($tmp_name,'up/'.$name);
            //操作成功后,提示成功
            echo "<script language=\"javascript\">alert('succeed')</script>";
        }else{
            //如果文件不符合类型或者上传过程中有错误,提示失败
            echo "<script language=\"javascript\">alert('failed')</script>";
        }
    }
?>
<!--设置提交文件的表单-->
<form enctype="multipart/form-data" method="post" name="uploadform">
<input type="file" name="uploadfile" value="Upload File">
<input type="submit" name="submit" value="Upload">
</form>

  详细说明:http://php.662p.com/thread-570-1-1.html

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

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),

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.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor