This is the fourth file of the system. Upload.php is responsible for the main, file name verification
, upload files and file addresses for archiving
<title>File Upload</title>
Uploaded columns $col, $upfile uploaded files, $writer author, $intro profile
$writer =substr (Htmlspecialchars ($writer), 0,20);
$intro =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);//host plus current directory
$cgiroot = "http://eccct.51.net/cgi-bin/";
$uploadto = ". /uploadfile/". $col." /";//Sub-directory uploaded to
$goback = "
The system will return in 3 seconds .... ";
Set_time_limit (300);//can last 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 1MB
". $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 name of the uploaded file must be zip or rar (lowercase)
". $goback);
}
$filename = $filesp [0]. $i. ".". $FILESP [1];
}
if ($i >0)
Echo ("Sorry, the file name you want to upload already exists,
The system automatically renames it as ". $filename.");
Check the end of rationality
if (!copy ($upfile, $uploadto. $filename)) Die ("
System error 03, please 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". $goback);
}
Copy ($flists, $flists. ". Bak ");
if (! $fp =fopen ($flists, "R")) {
Unlink ($uploadto. $filename);
Die ("error". $goback);
}
$filerc =explode (">", Fread ($fp, FileSize ($flists)));//uploaded archive data
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;
Number <作者<文件位置<投票计数<简介<文件大小<文件下载次数
<><><><><> <文件下载次数>
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 "
Delivery success
";
echo "file in". $cgiroot. $fileurl. ". $goback ";
File Transfer succeeded
?>
<><><><> <文件下载次数>
This is the last article of this article, mainly describes how to use the system, let us use a case to illustrate:
For example, we want to do flash work upload vote, then we just need to in. /uploadfile/(relative to the location of the system PHP file) A Flash subdirectory is built, and in which the following files are created: Flash.if (the caption that appears when the record appears), Flash.ip (voting IP record), FLASH.IPD (download IP record), Flash.lst (download file information record). Then use the View.php?col=flash to use the system, if you want to add new columns/user PHP works upload, just in. /uploadfile/under a different subdirectory PHP, and the corresponding file, and use view.php?col=php can be used</文件下载次数>
The above describes the voting system without the database of multi-user files free upload voting system 3, including the voting system content, I hope the PHP tutorial interested in a friend helpful.