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

Source: Internet
Author: User
Multi-user files without databases are freely uploaded to the voting system (3) This is the fourth file in the system. upload. php 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] = "";
$ 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 ="



The system will return in 3 seconds .... 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 ("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". $ cgiroot. $ 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 .. /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.