-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/RandomFileNameファイルパスではなく、ファイル名のみが含まれます(またはのようなものになります。ファイルを目的の宛先に移動するには、 copy の代わりにmove_uploaded_fileC:\Users\xxx\AppData\Local\Temp\RandomFileNameを使用します。

于 2013-03-24T16:01:16.990 に答える