Home > Backend Development > PHP Tutorial > Difference between switch and router Script to establish file exchange function (3)

Difference between switch and router Script to establish file exchange function (3)

WBOY
Release: 2016-07-29 08:33:27
Original
1264 people have browsed it

//do.php executes the uploaded file
When you press the submit button, the file will be uploaded from your computer to the temporary directory of the server.
The file name in the temporary directory is a temporary file. It should be accessed using the name value of the file field, in this case $myfile.
The real file name is accessed using the name value of the file field plus "_name", in this case $myfile_name.
Use the copy() function to copy the temporary file $myfile to the specified directory. The copied file name is $myfile_name.
Don’t forget to delete the temporary files when finished, otherwise you will have a lot of files you don’t want.
In addition, you must have read and write permissions on the directory you specify. Here it is /usr/local/apache/htdocs/file/


Save file

//Automatically jump to index.php after 3 seconds

< ;body bgcolor="#FFFFFF">


$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 the directory you specified.
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 "Upload file successfully, return to the main page after three seconds";
}
else {
echo"Upload file Unsuccessful, return to the main page after three seconds";
}
?>



//Sorry, everyone, I forgot to mention that you need to change php .ini file configuration
Remove the ";" in front of upload_tmp_dir=/tmp, and add the directory where the temporary files you want to use are stored at the end.
Also remove the ";" in front of upload_max_filesize =100M, and then add the maximum size of the file you want users to upload at the end.
I am using 100M, which is enough. ^_^.​

The above introduces the difference between switches and routers and the script (3) to establish the file exchange function, including the differences between switches and routers. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template