search
Homephp教程php手册jQuery Mobile + PHP实现文件上传

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

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

下面是html和php的代码

复制代码 代码如下:





               
               
               
               


       

              

                               

校园祭


                                首页
               

               

               

                                                                               enctype="multipart/form-data" data-inline="true"  data-ajax="false" />
                               

               

               

               

                               

创新实验


               

      



复制代码 代码如下:


        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,现在就可以将文件上传到服务器的文件夹了.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment