上传.php
<form enctype="multipart/form-data" action="uploader.php" method="POST">
Choose a file: <input name="uploadedfile" type="file" /><br />
Choose a file1: <input name="uploadedfile1" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
upload.php 表单的图像
上传者.php
mysql_select_db("test");
$target_path = "uploads/" . basename( $_FILES['uploadedfile']['name']);
$currentfile = $_FILES['uploadedfile']['name'];
$target_path1 = "upload1/" . basename( $_FILES['uploadedfile1']['name']);
$currentfile1 = basename( $_FILES['uploadedfile1']['name']);
$dbfiles = mysql_query("SELECT * FROM new WHERE amount='$currentfile' || amount='$currentfile1'");
if(mysql_num_rows($dbfiles) > 0 )
{
//what code should i place here??
}
else
{
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "file1: ".$_FILES['uploadedfile']['name']."<br>";
$file1 = basename( $_FILES['uploadedfile']['name']);
mysql_query("insert into new (amount) values('$file1')");
}
if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path1))
{
echo "file2: ".basename( $_FILES['uploadedfile1']['name']);
$file2 = basename( $_FILES['uploadedfile1']['name']);
mysql_query("insert into new (amount) values('$file2')");
}
}
我应该在这个 if 条件中放置什么代码,if(mysql_num_rows($dbfiles) > 0 ){ }
以便如果上传的文件的文件名已经存在,该文件应该自动更改其文件名,例如存在 abc.jpg,然后有人上传一个新文件但名称和类型与abc.jpg..相同,则新文件必须为abc_1.jpg...,如果有人上传与abc.jpg相同,则名称应为abc_2.jpg..abc_1.jpg必须是要保存到 mysql 的名称,abc_1.jpg 必须是要保存到准备好的文件夹的文件.. thx