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
?>