jQuery Mobile + PHP实现文件上传

这篇文章主要介绍了jQuery Mobile + PHP实现文件上传的方法实例,以及由于自己疏忽造成的问题的解决方法,这里推荐给大家,有需要的小伙伴参考下

很简单的一个小例子 jQuery Mobile + PHP 通过超全局 $_FILES 上传,然后用move_uploaded_file()方法把上传的图片移动到到本地服务器下的文件夹,

下面是html和php的代码

复制代码 代码如下:


<!DOCTYPE html>
<html>
<head>
                <meta charset = "utf-8">
                <link href="">
                <script src=""></script>
                <script src=""></script>
</head>
<body>
        <div data-role="page" >
               <div data-role="header"  >
                                <h1>校园祭</h1>
                                <a href="#pageone" data-rolr = button data-icon="home" >首页</a>
                </div>
                <div data-role="content" >
                <form action="upload_file.php" method="post" enctype="multipart/form-data" data-ajax="false">
                                <input   type="file"  runat="server" method="post"
                                               enctype="multipart/form-data" data-inline="true"  data-ajax="false" />
                                <center><button  data-inline="true"  >上传</button></center>
                </form>
                </div>
                <div data-role="footer" data-position="fixed" data-fullscreen="true">
                                <h1>创新实验</h1>
                </div>
       </div>
</body>
</html>

复制代码 代码如下:


<?php
        if ($_FILES["file"]["error"] > 0)
        {
                echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
                if (file_exists("upload/" . $_FILES["file"]["name"]))
                {
                        echo $_FILES["file"]["name"] . " already exists. ";
                }
                else
                {
                        move_uploaded_file($_FILES["file"]["tmp_name"],
                       "upload/".$_FILES["file"]["name"]);
                        echo "Stored in: "  ."upload/". $_FILES["file"]["name"];
                }
        }
}
?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ad1c51731c64134d05b2de18fa2e0b26.html