2013-03-24 45 views
-2

i am following link但得到這個錯誤 越來越PHP的圖片上傳

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'; 
     } 
    } 
} 
?> 
+0

你有「上傳」文件夾在「testimgupload」或有適當的權限.. ..? – alwaysLearn 2013-03-24 15:56:47

回答

1

$_FILES['fileField']['tmp_name']只包含文件名,而不是文件路徑(這將是像/tmp/RandomFileNameC:\Users\xxx\AppData\Local\Temp\RandomFileName爲該文件移動到你想要的目的地使用move_uploaded_file,而不是複印件。