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

php上传图片代码

时间:2016-04-05 19:43:58      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

html页面:

<html> 
<body> 
<form action="upload_file.php" method="post" 
enctype="multipart/form-data"> 
<label for="file">Filename:</label> 
<input type="file" name="file" id="file" /> 
<br /> 
<input type="submit" name="submit" value="Submit" /> 
</form> 
</body> 
</html> 

php处理页面:

<?php
    var_dump($_FILES);

    if(($_FILES[‘file‘][‘type‘] == "image/gif" ||
        $_FILES[‘file‘][‘type‘] == "image/jpeg" ||
        $_FILES[‘file‘][‘type‘] == "image/pjpeg" ||
        $_FILES[‘file‘][‘type‘] == "image/png") &&
       ($_FILES[‘file‘][‘size‘] < 200000))
    {
        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"];

            /* 判断文件是否存在,不存在则烤白过来
             * */
            if(file_exists("upload/".$_FILES[‘file‘][‘name‘]))
            {
                print_r("file already exitst!");
            }
            else
            {
                move_uploaded_file($_FILES[‘file‘][‘tmp_name‘],
                      "upload/".$_FILES[‘file‘][‘name‘]);
            }
        } 
    }
    else
    {
        print_r("不是图片文件类型或者文件超大!");
    }
?> 

 

php上传图片代码

标签:

原文地址:http://www.cnblogs.com/931it/p/5356301.html

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