Upload files first create a directory and upload it to the directory to _php tips

Source: Internet
Author: User
Tags mkdir
1, form section:
Copy Code code as follows:

<title>
My is Upfile app!!
</title>
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<body>
<form enctype= "Multipart/form-data" method= "post" action= "upfile_add.php" >
FileName: <input type= "text" name= "title"/>
Upload file: <input type= "file" name= "file"/>
<input type= "Submit" vlaue= "submitted"/>
</form>
</body>

2, processing the form page:
Copy Code code as follows:

<?php
$mkdir _file_dir = mkdir ('./img/'. $_post[' title '],0777); Get to the title, create a folder under the final directory to hold the category-specified file
$tmp _file_name = $_files[' file ' [' tmp_name '];//Get uploaded temporary file
$file _name = $_fi les[' file ' [' Name ']; The source file
$file _dir = './img/'. $_post[' title '. /'; The final Save directory
if (Is_dir ($file _dir))
{
Move_uploaded_file ($tmp _file_name, $file _dir. $file _name); Move files to the final save directory
$img _url = $file _dir. $file _name;
$link = mysql_connect ("localhost", "root", "");
mysql_select_db ("Fenye");
mysql_query ("Set names UTF8");
$insert = "INSERT into Upfiles (Title,img_url) VALUES (' {$_post[' title ']} ', ' {$img _url} ')";
mysql_query ($insert);//Deposit file path to database

?>
Related Article

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.