码迷,mamicode.com
首页 > Web开发 > 详细

php 文件上传

时间:2016-11-15 01:04:26      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:title   size   php 文件上传   echo   art   sse   har   val   set   

uploadForm.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <form action="upload_file.php" method="post" enctype="multipart/form-data">
            <label for="fileName">fileName:</label>
            <input type="file" id="fileName" name="file" /><br />
            <input type="submit" value="submit" />
        </form>
    </body>
</html>

upload_file.php

<?php
    //判断文件的类型,用户只能上传gif和jpeg的文件
    if((($_FILES[‘file‘][‘type‘] == ‘image/gif‘)||($_FILES[‘file‘][‘type‘] == ‘image/jpeg‘)||($_FILES[‘file‘][‘type‘] == ‘image/pjpeg‘))&&($_FILES[‘file‘][‘size‘]<2000000)){
        if($_FILES[‘file‘][‘error‘] > 0){
            echo "Error:" . $FILES[‘file‘][‘error‘]. ‘<br/>‘;
        }else{
            echo ‘Upload: ‘ . $_FILES[‘file‘][‘name‘].‘<br />‘;
            echo ‘Type: ‘ . $_FILES[‘file‘][‘type‘] . ‘<br />‘;
            echo ‘Size: ‘ . ($_FILES[‘file‘][‘size‘]/1024).‘Kb <br/>‘;
            echo ‘Stored in: ‘ . $_FILES[‘file‘][‘tmp_name‘] . ‘<br />‘;
            
            //判断是否存在
            if(file_exists(‘upload/‘ . $_FILES[‘file‘][‘name‘])){
                echo $_FILES[‘file‘][‘name‘]. ‘ is exist‘;
            }else{
                move_uploaded_file($_FILES[‘file‘][‘tmp_name‘] , ‘upload/‘.$_FILES[‘file‘][‘name‘]);
                echo ‘successed‘;
            }
        }
    }else{
        echo ‘fileType error or fileSize error‘;
    }
?>

 

php 文件上传

标签:title   size   php 文件上传   echo   art   sse   har   val   set   

原文地址:http://www.cnblogs.com/xudy/p/6063801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!