Home > Backend Development > PHP Tutorial > jQuery Mobile + PHP to implement file upload, _PHP tutorial

jQuery Mobile + PHP to implement file upload, _PHP tutorial

WBOY
Release: 2016-07-13 10:11:46
Original
883 people have browsed it

jQuery Mobile + PHP implements file upload,

A very simple example jQuery Mobile + PHP uploads through the super global $_FILES, and then uses the move_uploaded_file() method to move the uploaded image to a folder under the local server,

The following is the html and php code

Copy code The code is as follows:




                                                                                                                                                                                                                                             

                                                                                                                                                                                                                     
                     


          

                                                                                                                                                                                                                                                                in 

Campus Festival


                                                                                                                                                                                                                                                           in                                                                                                                                                                                                                                                                                                                         

                           

& Lt; input ID = "uploadimg" name = "file" type = "file" runt = "server" method = "post"
enctype="multipart/form-data" data-inline="true" data-ajax="false" />
                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                                                            

Innovative Experiment


                                                                                                                                                                                         







Copy code

The code is as follows:

        if ($_FILES["file"]["error"] > 0)
        {
                echo "Return Code: " . $_FILES["file"]["error"] . "
";
        }
        else
        {
               echo "Upload: " . $_FILES["file"]["name"] . "
";
                echo "Type: " . $_FILES["file"]["type"] . "
";
               echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";
                echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";
                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"];
                }
        }
}
?>

代码很简单,但是使用过程中却发现一个问题,自己试了好久都上传不了
询问了小伙伴后,发现问题所在是文件权限不足,从而限制了网页上传图片到文件夹中.所以解决办法就是把文件夹的权限问题解决掉.

复制代码 代码如下:

$ cd /var/www
$ sudo chmod -R  777  html

ok,现在就可以将文件上传到服务器的文件夹了.

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/926875.htmlTechArticlejQuery Mobile + PHP实现文件上传, 很简单的一个小例子 jQuery Mobile + PHP 通过超全局 $_FILES 上传,然后用move_uploaded_file()方法把上传的图片移动到...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template