多重上传.php
下面的代码是multiple_upload.php,它有2个上传按钮和一个提交按钮。它的实际图片:
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>multiple Files Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td>Select file
<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
multiple_upload_ac.php
此代码将处理您放入这行代码中的文件,<input name="ufile[]" type="file" id="ufile[]" size="50" />
它将保存在我的上传文件夹中。
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
// Use this code to display the error or success.
$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
if($filesize1 || $filesize2!= 0)
{
echo "We have recieved your files";
}
else {
echo "ERROR.....";
}
// What files that have a problem? (if found)
if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}
if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}
?>
这是我的问题:例如,如果可能,我上传 samplefile.ppt 并且其他用户上传相同的文件名和文件类型(samplefile.ppt)。如果可能,新上传的文件名将像 samplefile(1)。 ppt 或 samplefile_1.ppt 因为已经存在一个文件,当其他用户再次上传时,该文件将变为 samplefile(2).ppt 或 samplefile_2.ppt。谢谢你