Form part:
The code is as follows:
<Html>
<Head>
<Title>
My is upfile app !!
</Title>
<Meta http-equiv = "content-type" content = "text/html; charset = utf-8"/>
</Head>
<Body>
<Form enctype = "multipart/form-data" method = "post" action = "upfile_add.php tutorial">
File name: <input type = "text" name = "title"/>
Upload file: <input type = "file" name = "file"/>
<Input type = "submit" vlaue = "submit"/>
</Form>
</Body>
</Html>
2. Process the form page:
The code is as follows:
<? Php
$ Mkdir_file_dir = mkdir ('. /img /'. $ _ post ['title'], 0777); // obtain the title and create a folder under the final directory to store the file specified by the category.
$ Tmp_file_name = $ _ files ['file'] ['tmp _ name']; // Get the uploaded temporary file
$ File_name = $ _ files ['file'] ['name']; // source file
$ File_dir = './img/'. $ _ post ['title']. '/'; // Finally save the Directory
If (is_dir ($ file_dir ))
{
Move_uploaded_file ($ tmp_file_name, $ file_dir. $ file_name); // move the file to the final save Directory
$ Img_url = $ file_dir. $ file_name;
$ Link = mysql tutorial _ 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); // store the file path in the database tutorial
}
?>