电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> PHP>>php实例-多文件上传:

php实例-多文件上传

来源:www.cncfan.com | 2006-1-11 | (有3472人读过)

<?
// 本例来自与ZEND网站,由HUNTE整理

// ASP-style tags are okay in PHP 3.0.4 and above; some HTML editors recognize these tags

// File Upload Script for PHP/3 for Windows

// Released under the terms of the public GNU license
// Based upon code written by Rasmus Lerdorf
// Modified for Windows by Michael Grier
// E-mail: bigmike@bigmweb.com

// You need to write-enable a directory, named "upload", below the one you place this script in
// On Windows NT, you can do this with a DOS program named CACLS
// Directions for this can be found at "http://www.bigmweb.com/home/cacls.html"



if($action1){
// if files have been uploaded, process them

?>
<html>
<head>
<title>File Upload Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p><font face="Arial, Helvetica, sans-serif"><font size="+1">File
Upload Results</font>



<?
set_time_limit(60);
// make reasonably sure the script does not time out on large files
$path1 = dirname($PATH_TRANSLATED)."/upload/";
//print $PATH_TRANSLATED;
//print $path1."
";
// assign our path in a form PHP for Windows understands

for($i=1;$i<3;$i++)
{
$temp1="file".$i;
$temp2="file".$i."_name";
$source=$$temp1;
$source_name=$$temp2;
// print $temp."=".$$temp."
";

//print $file1_name;
//print $file2_name;
//exit;

//*****************
//$source = $file1;
//$source_name = $file1_name;
print $source."
";
print $source_name;
//exit;
if(($source <> "none")&&($source <> ""))
{
// see if the file exists; non-existing file has name of "none"
if($error1 <> 1)
{
// no need to copy a file if directory not write-enabled
$dest = $path1.$source_name;
// append file name to our path

if(copy($source,$dest)){
// copy the file from the temp directory to the upload directory, and test for success
echo "$source has been uploaded
\n";
$imagesize = getimagesize($dest);
switch($imagesize[2])
{
case 0:
echo "
Image is a unknown
";
unlink($dest);
exit;
case 1:
echo "
Image is a GIF
";
echo "$dest has a width of $imagesize[0]
";
echo "$dest has a height of $imagesize[1]
";
$newname = $path1;
$newname .=$i.time() . ".gif";
if(copy($dest,$newname))
{
echo "
GIF Rename Successful from $dest to $newname";
}else {
echo "
GIF Rename Unsuccessful";
}
unlink ($dest);
break;
case 2:
echo "
Image is a JPG
";
echo "$dest has a width of $imagesize[0]
";
echo "$dest has a height of $imagesize[1]
";
$newname = $path1;
$newname .=$i.time() . ".jpg";
if(copy($dest,$newname))
{
echo "
JPG Rename Successful from $dest to $newname";
}else {
echo "
JPG Rename Unsuccessful";
}
unlink ($dest);
break;
case 3:
echo "
Image is a PNG
";
echo "$dest has a width of $imagesize[0]
";
echo "$dest has a height of $imagesize[1]
";
$newname = $path1;
$newname .=time() . ".png";
if(copy($dest,$newname))
{
echo "
PNG Rename Successful from $dest to $newname";
}else {
echo "
PNG Rename Unsuccessful";
}
unlink ($dest);
break;
}
}else {
echo "Upload directory not write-enabled\n";
// you need to write-enable the upload directory
$error1 = 1; // set flag
}
}
unlink($source);
// delete the file from the temp directory
}

?>
<image src="upload/<? print basename($newname)?>">
<?
} //end for
?>

<a href="fup.php">Back</a>
</font></p>
</body>
</html>

<?
}
else {

?>

<html>
<head>
<title>File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p><font face="Arial, Helvetica, sans-serif"><font size="+1">File
Upload</font>


If your browser is upload-enabled, you will see "Browse"
(Netscape, Internet Explorer) or ". . ." (Opera) buttons below.
Use them to select file(s) to upload, then click the "Upload"
button. After the files have been uploaded, you will see a results screen.

<form method="post" enctype="multipart/form-data" action="fup.php">
<input type="hidden" name="MAX_FILE_SIZE" value="800000">
<input type="hidden" name="action1" value="1">
File 1: <input type="file" name="file1" size="30">

File 2: <input type="file" name="file2" size="30">



<input type="submit" value="Upload">
</form>
</font></p>
</body>
</html>

<?

}

?>
PHP热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2022 电脑爱好者 版权所有 备案号:鲁ICP备09059398号