-1

上传.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

我在这里得到了想法和代码http://www.tizag.com/phpT/fileupload.php?MAX_FILE_SIZE=100000&uploadedfile=NeroMediaHub._63C8A7B0BBE5459F9AC436392B2FF50D.exe

4

2 回答 2

0

尝试这个

<?php
$target_path = "uploads/" . basename( $_FILES['uploadedfile']['name']); 
$target_path1 = "uploads/" . basename( $_FILES['uploadedfile1']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
}
else{
    echo "There was an error uploading the file, please try again!";
}

if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path1)) {
    echo "The file ".  basename( $_FILES['uploadedfile1']['name']). 
    " has been uploaded";
}
else{
    echo "There was an error uploading the file1, please try again!";
}
?>
于 2012-11-09T02:01:36.597 回答
0

用这样的东西测试......

<?php
    $target_path = "uploads/" . basename( $_FILES['uploadedfile']['name']);
    $target_path1 = "uploads/" . basename( $_FILES['uploadedfile1']['name']);
    $file_saved = false;

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
    {
        echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";
        $file_saved = true;
    }
    if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path1))
    {
        echo "The file ".  basename( $_FILES['uploadedfile1']['name']). 
" has been uploaded";
        $file_saved = true;
    }
    if (!$file_saved)
    {
        echo "There was an error uploading the file, please try again!";
    }
?>
于 2012-11-09T02:02:19.347 回答