Free upload voting system with multiple user files without database (3)

Source: Internet
Author: User
Tags explode file size file upload file url php file rar trim zip
This is the fourth document of the system. Upload.php is primarily responsible for the verification of filename
, uploading file and file address archive

<body><div style= "width:750" ><center>
<?php
Uploaded column $col, $upfile uploaded file, $writer author, $intro profile


$writer =substr (Htmlspecialchars ($writer), 0,20);
$intro =substr (Htmlspecialchars ($intro), 0,100);

Maximum file length for $maxsize =512000*2;//
$pathtemp =explode ("/", $HTTP _env_vars["Path_info"));
$pathtemp [sizeof ($PATHTEMP) -1]= "";
$cgiroot = "http://". $HTTP _host.implode ("/", $pathtemp);/host plus current directory



$cgiroot = "http://eccct.51.net/cgi-bin/";
$uploadto = ". /uploadfile/". $col." /";//uploaded to subdirectories

$goback = "<br><br><br><br><center> system will return ....</center><script> in 3 seconds settimeout (' location.href= "view.php?col=". $col. "" ", 3000) </script>;




Set_time_limit (300);//can last 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> system automatically renamed it". $filename. " </font> ");

Check Rationality end

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". $goback);
}


Copy ($flists, $flists. " Bak ");
if (! $fp =fopen ($flists, "R")) {
Unlink ($uploadto. $filename);
Die ("error". $goback);
}
$filerc =explode (">", Fread ($fp, FileSize ($flists))/uploaded file
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;
Numbering < author < file Locations < Polling count < Introduction < file size < download times

if (! $fp =fopen ($flists, "w")) {
Unlink ($uploadto. $filename);
Copy ($flists. ". Bak ", $flists);
Die ("error". $goback);
}

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

Fclose ($FP);


End of Write file list


File transfer

echo "


echo "File in <a href=". $fileurl. " > ". $cgiroot. $fileurl." </a> $goback ";
File Transfer succeeded




?>
</center>
</div>
</body>

This is the last article in this article, mainly describes how to use the system, let us use a case to illustrate:

For example, we want to do the flash work upload vote, then we only need to be in the. /uploadfile/(relative to the system PHP file location) under the subdirectory to build a flash subdirectory, and in which the following files are created: Flash.if (the caption appears when the record is displayed), Flash.ip (vote IP record), FLASH.IPD (download IP record), Flash.lst (download file information record). Then use the View.php?col=flash can use the system, if you want to add columns/user PHP works upload, just in ... /uploadfile/under a separate subdirectory PHP, and the corresponding file, and use view.php?col=php 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.