-2

我正在关注链接,但收到此错误

Warning: copy(upload/83459755231.jpg) [function.copy]: failed to open stream: No such file or directory in K:\PHP WAMP\wamp\www\testimgupload\testimgupload\upload_file_script.php on line 36

那条线是

    copy($_FILES['fileField']['tmp_name'],'upload/'.$newFileName);

它有什么问题?

我的脚本是

<?php //=============Configuring Server and Database=======
$host = 'localhost';
$user = 'root';
$password = '';

$database = 'DBNAME';

$conn = mysql_connect($host,$user,$password) or die('Server Information is not Correct');
mysql_select_db($database,$conn) or die('Database Information is not correct');

//===============End Server Configuration============

if(isset($_POST['btnAdd']))
{
    $myFile = $_FILES['fileField']['name']; // Storing name into variable

    //====If you want to change the name of the File====
    $anyNum = rand(20,500789000); //Will generate a random number between 20and 500789000

    $newFileName = $anyNum.$myFile;//===New string is concatenated====
    //===Following Function will check if the File already exists========

    if (file_exists("upload/".$newFileName))
    {
        echo $newFileName." already exists. ";
    }

    //======If file already exists in your Folder, It will return zero and Will not take any action===
    //======Otherwise File will be stored in your given directory and Will store its name in Database===
    else
    {

        $query = "insert into tblfileupload(file_name) values ('$newFileName')";

        $res = mysql_query($query);

        copy($_FILES['fileField']['tmp_name'],'upload/'.$newFileName);
        //===Copy File Into your given Directory,copy(Source,Destination)

        if($res>0)
        {
            //====$res will be greater than 0 only when File is uploaded Successfully====:)
            echo 'You have Successfulluy Uploaded File';
        }
    }
}
?>
4

1 回答 1

1

$_FILES['fileField']['tmp_name']只包含文件名,而不是文件路径(类似于/tmp/RandomFileNameor C:\Users\xxx\AppData\Local\Temp\RandomFileName。使用move_uploaded_file而不是 copy 将文件移动到您想要的目的地。

于 2013-03-24T16:01:16.990 回答