SoFunction
Updated on 2025-04-08

Scripts to establish file exchange function (III)

//Execute the uploaded file
When you press the submit button, the file will be uploaded from your computer to the server's temporary directory.
The file name in the temporary directory is a temporary file. It should be accessed using the name value of the file field, here $myfile.
The real file name uses the name value of the file field plus "_name" to access it, here $myfile_name.
Use the copy() function to copy the temporary file $myfile to the specified directory, and the copied file name is $myfile_name.
Don't forget to delete the temporary files after you are done, otherwise you will have many files you don't want.
In addition, you must have read and write permissions to the directory you specified. Here is /usr/local/apache/htdocs/file/



<html>
<head>
<title>Save file</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="refresh" content="3"; url="> //Redirect to automatically after 3 seconds
</head>
<body bgcolor="#FFFFFF">
<center>
<?
$db=mysql_connect("$hostname","$user","$password") or die("Cannot connect to 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 have formulated.
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 "The file upload is successful and returns to the main page after three seconds";
}
else {
echo "Uploading the file unsuccessfully, return to the main page after three seconds";
}
?>  
</center>
</body>
</html>

//sorry, everyone, I forgot to say that you want to change the configuration of the file
Remove the upload_tmp_dir=/tmp; and add the directory you want to use to store the temporary file you want to use.
Also, remove the upload_max_filesize = 100M front; and then add the maximum size of the file you want the user to upload.
I used 100M, that's enough. ^_^.