Using jquery Mobile + PHP to upload a mobile file example tutorial

Source: Internet
Author: User
Tags file permissions

A very simple example of jQuery mobile + PHP upload via Hyper-global $_files, and then use the Move_uploaded_file () method to move the uploaded image to a folder under the local server,

Here is the HTML code

The code is as follows Copy Code
<! DOCTYPE html>
<meta charset = "Utf-8" >
<link rel= "stylesheet" href= "Http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" >
<script src= "Http://code.jquery.com/jquery-1.8.3.min.js" ></script>
<script src= "Http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js" ></script>
<body>
<div data-role= "page" id= "Upload" >
<div data-role= "Header" >
<a href= "#pageone" DATA-ROLR = button data-icon= "Home" class= "Ui-btn-left" > Homepage </a>
</div>
<div data-role= "Content" >
<form action= "upload_file.php" method= "post" enctype= "Multipart/form-data" data-ajax= "false" >
<input id= "uploadimg" name= "file" type= "file" runat= "server" method= "POST"
Enctype= "Multipart/form-data" data-inline= "true" data-ajax= "false"/>
<center><button data-inline= "true" > Upload </button></center>
</form>
</div>
<div data-role= "Footer" data-position= "fixed" data-fullscreen= "true" >
</div>
</div>
</body>


Code for PHP

The code is as follows Copy Code
<?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"];
}
}
}
?>


The code is very simple, but the use of the process found a problem, I tried for a long time can not upload. Asked the small partner, found that the problem is insufficient file permissions, thereby restricting the page upload pictures to the folder. So the solution is to remove the permissions on the folder.

The code is as follows Copy Code
$ cd/var/www
$ sudo chmod-r 777 HTML


OK, you can upload the file to the server folder now.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.