Free uploading of multi-user files without databases to the voting system (3)

Source: Internet
Author: User

This is the fourth file in the system. upload. php is mainly responsible for file name verification.
, Archiving of uploaded files and file addresses

<Html>
<Head> <title> File Upload </title>
<Body> <div style = "width: 750"> <center>
<? Php
// Uploaded columns $ col, $ upfile files, $ writer, $ intro Introduction


$ Writer = substr (htmlspecialchars ($ writer), 0, 20 );
$ Ino = substr (htmlspecialchars ($ intro), 0,100 );

$ Maxsize = 512000*2; // maximum file length
$ Pathtemp = explode ("/", $ HTTP_ENV_VARS ["PATH_INFO"]);
$ Pathtemp [sizeof ($ pathtemp)-1] = "";
$ Cgiroot = "http: //". $ HTTP_HOST.implode ("/", $ pathtemp); // Add the current directory to the host



// $ Cgiroot = "http://eccct.51.net/cgi-bin ";
$ Uploadto = "../uploadfile/". $ col. "/"; // subdirectory to which the file is uploaded

$ Goback = "<br> <center> the system returns results in 3 seconds .... </center> <script> setTimeout ('location. href = "view. php? Col = ". $ col." "', 3000) </script> ";




Set_time_limit (300); // it can last for five minutes











// If (! Is_dir ($ uploadto) mkdir ($ uploadto, 0755 );

If ($ upfile_size> $ maxsize)
Die ("
$ Filename = $ upfile_name;
$ I = 0;
While (file_exists ($ uploadto. $ filename )){
$ I ++;

$ Filesp = explode ('.', trim ($ upfile_name ));
// Echo $ filesp [sizeof ($ filesp)-1];
// Echo $ filesp [sizeof ($ filesp)-1]! = "Zip ";
// Echo $ filesp [sizeof ($ filesp)-1]! = "Rar ";

If (trim ($ filesp [sizeof ($ filesp)-1])! = "Zip") & (trim ($ filesp [sizeof ($ filesp)-1])! = "Rar ")){

Die ("
}

$ Filename = $ filesp [0]. $ I. ".". $ filesp [1];

}


If ($ I> 0)
Echo ("<font color = red> sorry, the file name you want to upload already exists. <br> the system automatically renames it ". $ filename. "</font> ");

// Check rationality ends

If (! Copy ($ upfile, $ uploadto. $ filename) die ("
// Write File List
$ Fileurl = $ uploadto. $ filename; // File url
$ Flists = $ uploadto. $ col. ". lst"; // file list location

For ($ I = 0; $ I <100 &&! File_exists ($ flists); $ I ++ );
If ($ I = 99 ){
Unlink ($ uploadto. $ filename );
Die ("system error 00". $ goback );
}


Copy ($ flists, $ flists. ". bak ");
If (! $ Fp = fopen ($ flists, "r ")){
Unlink ($ uploadto. $ filename );
Die ("error 01". $ goback );
}
$ Filerc = explode (">", fread ($ fp, filesize ($ flists); // uploaded file information
Fclose ($ fp );

Unlink ($ flists );

$ Firstrec = explode ("<", $ filerc [0]);

If (! $ Firstrec [0]) $ id = 1;
Else $ id = $ firstrec [0] + 1;

$ Oldinfo = implode (">", $ filerc );

$ Newinfo = $ id. "<". $ writer. "<". $ filename. "<0 <". $ intro. "<". $ upfile_size. "<0> ". $ oldinfo;
// No. <author <File Location <voting count <overview <file size <file download times

If (! $ Fp = fopen ($ flists, "w ")){
Unlink ($ uploadto. $ filename );
Copy ($ flists. ". bak", $ flists );
Die ("error 02". $ goback );
}

Fwrite ($ fp, trim ($ newinfo ));

Fclose ($ fp );


// The Write File List ends.


// File Transfer

Echo "


Echo "file in <a href =". $ fileurl. ">". $ cgiroot. $ fileurl. "</a>. $ goback ";
// File transfer successful




?>
</Center>
</Div>
</Body>
</Html>

This is the last article in this article. It mainly introduces how to use the system. Let's use an example to illustrate it:

For example, if we want to upload and vote for flash files, we only need .. /uploadfile/(relative to the location of the system PHP file) create a flash subdirectory and create the following files: flash. if (the title displayed when the record is displayed), flash. ip (Voting ip records), flash. ipd (download ip records), flash. lst (download file information record ). then use view. php? Col = flash, you can use the system. If you want to add a new column/user to upload php files, you only need .. /uploadfile/create another subdirectory php, and the corresponding file, and use view. php? Col = php.

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.