Create a file exchange script (3 ). When you press the submit button, the files uploaded by do. php will be uploaded from your computer to the temporary directory on the server. The file name in the temporary directory is a temporary file // do. php file for Upload
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/
Save files
// Automatically jump to index. php in 3 seconds
$ 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 ";
}
?>
// 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. ^_^.
When 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...