Script to establish file Exchange capabilities (iii) _php Foundation

Source: Internet
Author: User
Tags save file
do.php execution of uploaded files
When you press the Submit button, the file will be uploaded to the server's temporary directory from your computer.
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 for $myfile.
The real file name uses the name value of the file field plus "_name" to access it, here for $myfile_name.
Use the copy () function to copy the temporary file $myfile to the specified directory, with the file named $myfile_name.
Don't forget to delete the temporary files when you're done, or you'll have a lot of files you don't want.
In addition, you must have read and write access to the directory you specify. This is/usr/local/apache/htdocs/file/.



<title> Save File </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<meta http-equiv= "Refresh" content= "3"; url=index.php >//3 seconds to automatically jump to index.php
<body bgcolor= "#FFFFFF" >
<center>
?
$db =mysql_connect ("$hostname", "$user", "$password") or Die ("Unable to connect to the database");
mysql_select_db ("Yourdatabase", $db) or Die ("Cannot open database");
If ($myfile!= "None") {
Copy ($myfile, "/usr/local/apache/htdocs/file/$myfile _name")//Copy the temporary file to the directory you made.
Unlink ($myfile);//Delete temporary files
$sql = "INSERT into Upfile (Id,filename,fileshow,date,uploader,type) VALUES (', ' $myfile _name ', ' $fileshow ', ' $date ', ' $ Uploader ', ' $type ');
$result =mysql_query ($sql);
echo "uploaded the file successfully, three seconds to return to the main page";
}
else {
echo "Upload file is unsuccessful, return to main page after three seconds";
}
?>
</center>
</body>

Sorry, gentlemen, forget to say that you want to change the configuration of the php.ini file
Put the upload_tmp_dir=/tmp in front of it, remove it, and add the contents of the temporary file you want to use in the back.
Still have to put upload_max_filesize =100m in front of; remove, then add the maximum size of the file you want the user to upload.
I'm using 100M, that's enough. ^_^.

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.