一个PHP文件上载的类
时间:2007-02-17 来源:PHP爱好者
<?php
/*
* Topic: File uploading class
* Author: [email protected]
* Modified: 14-8-2000
*
*/
// --------------------------------------------------------------------------------------------
// look & feel
// --------------------------------------------------------------------------------------------
function myHeader(){
?>
<HTML>
<HEAD>
<TITLE>PHP - file upload</TITLE>
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 10pt }
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<CENTER>
<?php
}
function myFooter(){
?>
</CENTER>
</BODY>
</HTML>
<?php
}
// --------------------------------------------------------------------------------------------
// upload class
// --------------------------------------------------------------------------------------------
class upload {
function myReport()
{
global $PHP_SELF, $userfile, $userfile_name, $newname, $userfile_size, $userfile_type, $dest_path;
?>
<TABLE>
<TR><TD><b>upload report</b>
<TR><TD>upload tmp file:</TD><TD><?php echo $userfile; ?></TD>
<TR><TD>file name:</TD><TD><?php echo $userfile_name; ?></TD>
<TR><TD>target file name:</TD><TD><?php echo $newname; ?></TD>
<TR><TD>target directory:</TD><TD><?php echo $dest_path; ?></TD>
<TR><TD>file size:</TD><TD><?php echo $userfile_size; ?></TD>
<TR><TD>file type:</TD><TD><?php echo $userfile_type; ?></TD>
<TR><TD>
<TR><TD><a href="<?php echo basename($PHP_SELF); ?>">upload again</a></TD>
</TABLE>
<?php
}
function myForm()
{
global $PHP_SELF, $dest_path, $dest_file, $userfile;
$read_only = "yes"; // do not let others to change the target filename
$dest_path = "c:tmp"; // target file destination path
$dest_file = "test.csv"; // target file name
$file_size = "100000"; // upload size limit
?>
<TABLE>
<FORM ENCTYPE="multipart/form-data" ACTION="<?php echo basename($PHP_SELF); ?>" METHOD=POST>
<INPUT TYPE="hidden" name="go" value="1">
<INPUT TYPE="hidden" name="dest_path" value="<?php echo $dest_path; ?>">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="<?php echo $file_size; ?>">
<TR>
<TD><b>file upload</b></TD>
<TD></TD>
<TR>
<TD>file:</TD>
<TD><INPUT TYPE="File" name="userfile" size="30" maxlength="255"></TD>
<TR>
<TD>target filename:</TD>
<TD><INPUT TYPE="Text" name="newname" size="30" maxlength="255" value="<?php echo $dest_file; ?>" <?php echo($read_only == "yes" ? 'READONLY' : '); ?> ></TD>
<TR>
<TD>upload diretory:</TD>
<TD><?php echo $dest_path; ?></TD>
<TR>
<TD colspan="2" align="CENTER"><INPUT TYPE="submit" VALUE="upload"></TD>
</FORM>
</TABLE>
<?php
}
function myUpload()
{
global $userfile, $newname, $dest_path;
$upload_path = "c:hostapachehtdocstmp";
if (!copy( $upload_path.basename($userfile), $dest_path.$newname)) echo "failed to copy file<br>n";
}
}
// --------------------------------------------------------------------------------------------
// main
// --------------------------------------------------------------------------------------------
$this = new upload;
switch ($HTTP_POST_VARS["go"]):
case (1):
$HTTP_POST_VARS["go"] = 0;
myHeader();
$this-> myUpload();
$this-> myReport();
myFooter();
break;
default:
myHeader();
$this-> myForm();
myFooter();
endswitch;
?>
php爱好者站 http://www.phpfans.net 为phper提供一切资讯.
/*
* Topic: File uploading class
* Author: [email protected]
* Modified: 14-8-2000
*
*/
// --------------------------------------------------------------------------------------------
// look & feel
// --------------------------------------------------------------------------------------------
function myHeader(){
?>
<HTML>
<HEAD>
<TITLE>PHP - file upload</TITLE>
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 10pt }
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<CENTER>
<?php
}
function myFooter(){
?>
</CENTER>
</BODY>
</HTML>
<?php
}
// --------------------------------------------------------------------------------------------
// upload class
// --------------------------------------------------------------------------------------------
class upload {
function myReport()
{
global $PHP_SELF, $userfile, $userfile_name, $newname, $userfile_size, $userfile_type, $dest_path;
?>
<TABLE>
<TR><TD><b>upload report</b>
<TR><TD>upload tmp file:</TD><TD><?php echo $userfile; ?></TD>
<TR><TD>file name:</TD><TD><?php echo $userfile_name; ?></TD>
<TR><TD>target file name:</TD><TD><?php echo $newname; ?></TD>
<TR><TD>target directory:</TD><TD><?php echo $dest_path; ?></TD>
<TR><TD>file size:</TD><TD><?php echo $userfile_size; ?></TD>
<TR><TD>file type:</TD><TD><?php echo $userfile_type; ?></TD>
<TR><TD>
<TR><TD><a href="<?php echo basename($PHP_SELF); ?>">upload again</a></TD>
</TABLE>
<?php
}
function myForm()
{
global $PHP_SELF, $dest_path, $dest_file, $userfile;
$read_only = "yes"; // do not let others to change the target filename
$dest_path = "c:tmp"; // target file destination path
$dest_file = "test.csv"; // target file name
$file_size = "100000"; // upload size limit
?>
<TABLE>
<FORM ENCTYPE="multipart/form-data" ACTION="<?php echo basename($PHP_SELF); ?>" METHOD=POST>
<INPUT TYPE="hidden" name="go" value="1">
<INPUT TYPE="hidden" name="dest_path" value="<?php echo $dest_path; ?>">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="<?php echo $file_size; ?>">
<TR>
<TD><b>file upload</b></TD>
<TD></TD>
<TR>
<TD>file:</TD>
<TD><INPUT TYPE="File" name="userfile" size="30" maxlength="255"></TD>
<TR>
<TD>target filename:</TD>
<TD><INPUT TYPE="Text" name="newname" size="30" maxlength="255" value="<?php echo $dest_file; ?>" <?php echo($read_only == "yes" ? 'READONLY' : '); ?> ></TD>
<TR>
<TD>upload diretory:</TD>
<TD><?php echo $dest_path; ?></TD>
<TR>
<TD colspan="2" align="CENTER"><INPUT TYPE="submit" VALUE="upload"></TD>
</FORM>
</TABLE>
<?php
}
function myUpload()
{
global $userfile, $newname, $dest_path;
$upload_path = "c:hostapachehtdocstmp";
if (!copy( $upload_path.basename($userfile), $dest_path.$newname)) echo "failed to copy file<br>n";
}
}
// --------------------------------------------------------------------------------------------
// main
// --------------------------------------------------------------------------------------------
$this = new upload;
switch ($HTTP_POST_VARS["go"]):
case (1):
$HTTP_POST_VARS["go"] = 0;
myHeader();
$this-> myUpload();
$this-> myReport();
myFooter();
break;
default:
myHeader();
$this-> myForm();
myFooter();
endswitch;
?>
php爱好者站 http://www.phpfans.net 为phper提供一切资讯.
相关阅读 更多 +