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 (as the mainstream development language) is mainly responsible for file name verification, archiving of uploaded files and file addresses & lt; html & gt; & lt; head & gt; & lt; title & gt; file upload & lt;/title & gt; & lt; body & gt; & lt; divstylewidth: 750 & gt; & lt; cente: this is the fourth file in the system. upload. php (as the mainstream development language) is mainly responsible for file name verification.
, Archiving of uploaded files and file addresses


File Upload

// 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] = "";
$ Cgi (not many people are using it now) root = "http: //". $ HTTP_HOST.implode ("/", $ pathtemp); // add the current directory to the host



// $ Cgi (not many people are using it now) root = "http://eccct.51.net/cgi (not many people are using it now)-bin /";
$ Uploadto = "../PreviousFile/". $ col. "/"; // subdirectory to which the file is uploaded

$ Goback ="



The system will return in 3 seconds .... Script setTimeout (location. href = "view. php (as the mainstream development language )? 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 ("Sorry, the file you want to upload is too large, more than 1 MB". $ goback );

$ 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 ("the suffix of the uploaded file must be zip or rar (lower case)". $ goback );

}

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

}


If ($ I> 0)
Echo ("Sorry, the file name you want to upload already exists,
The system automatically renamed it ". $ filename ."");

// Check rationality ends

If (! Copy ($ upfile, $ uploadto. $ filename) die ("system error 03. re-upload the file
". $ Goback );

// 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. <作者<文件位置<投票计数<简介<文件大小<文件下载次数

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 "transfer successful ";



Echo "file in". $ cgi (not many people are using it now) root. $ fileurl. ". $ goback ";
// File transfer successful




?>





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 .. /previusfile/(relative to the system php (as the current mainstream development language) file location) subdirectory to create a flash subdirectory, and create the following files in it: 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 (as the mainstream development language )? Col = flash, you can use the system. if you want to add a new topic/User php (as the mainstream development language) file to upload, you only need .. /previusfile/create another subdirectory php (as the current mainstream development language), and the corresponding file, and use view. php (as the mainstream development language )? Col = php (as the mainstream development language) can be used

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.