// Do. php executes the uploaded file
After you press the submit button, the file will be uploaded from your computer to the temporary directory on the server.
The file name in the temporary directory is a temporary file. You should use the name value of the file field to access it. Here, it is $ myfile.
The actual file name is accessed by adding "_ name" to the name value of the file field. $ myfile_name is used here.
Use the copy () function to copy the temporary file $ myfile to the specified directory. The copied file name is $ myfile_name.
Do not forget to delete the temporary files after they are completed. Otherwise, you will have many files you do not want.
In addition, you must have read and write permissions on the specified directory. Here is/usr/local/apache/htdocs/file/
<Html>
<Head>
<Title> Save the file </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Meta http-equiv = "refresh" content = "3"; url = index. php "> // automatically jump to index. php 3 seconds later
</Head>
<Body bgcolor = "# FFFFFF">
<Center>
<?
$ Db = mysql_connect ("$ hostname", "$ user", "$ password") or die ("unable to connect to Database ");
Mysql_select_db ("yourdatabase", $ db) or die ("unable to Open Database ");
If ($ myfile! = "None "){
Copy ($ myfile, "/usr/local/apache/htdocs/file/$ myfile_name"); // copy the temporary file to your specified directory.
Unlink ($ myfile); // delete a temporary file
$ SQL = "insert into upfile (id, filename, fileshow, date, uploader, type) values ('', '$ myfile_name', '$ fileshow', '$ date ', '$ upload',' $ type ')";
$ Result = mysql_query ($ SQL );
Echo "the file is uploaded successfully. Three seconds later, return to the home page ";
}
Else {
Echo "failed to upload the file. Three seconds later, return to the home page ";
}
?>
</Center>
</Body>
</Html>
// Sorry, everybody, forget to talk about it. You need to change the configuration of the php. ini file.
Remove the directory before upload_tmp_dir =/tmp and add the directory where you want to store the temporary files.
Remove the file before upload_max_filesize = m, and add the maximum size of the file to be uploaded.
I use 100 M. That's enough. ^_^.