Script for creating the file exchange function (III) _ PHP Tutorial

Source: Internet
Author: User
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...

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.