2015-10-23 72 views
1

我得到了錯誤,同時從tmp目錄移動到的位置......這裏是我的代碼未定義指數:TMP而從臨時移動文件位置

if(isset($_POST['upload'])) 
{ 
    $name = $_POST['name']; 
    $album_id = $_POST['album']; 
    $file = $_FILES['file']['name']; 
    $file_type = $_FILES['file']['type']; 
    $file_size = $_FILES['file']['size']; 
    $file_tmp = $_FILES['file']['tmp']; 
    $random_name = rand(); 

    if(empty($name) || empty($file)) 
    { 
     echo "Please fill all the fields"; 
    } 
    else 
    { 
     move_uploaded_file($file_tmp, 'uploads/'.$random_name.'.jpg');//Error in this line 
     mysqli_query($con,"INSERT INTO `p_photos` (`name`,`album_id`,`url`) VALUES ('$name','$album_id','$random_name.jpg')"); 
     echo 'Photo Uploaded successfully!<br /><br />';   

    } 

} 

哪裏我做錯....是有一個文件夾「上傳」

+0

的**未定義指數**錯誤將來自試圖訪問索引['tmp'],如在這條線:'$ file_tmp = $ _FILES [ '文件'] [ 'TMP'];'。檢查以確保'$ file_tmp'被正確定義。 –

+0

是的,我們正確。我哪裏做錯了? – shaiToro

+0

http://php.net/manual/en/features.file-upload.php –

回答

2

哪裏我做錯....是有一個文件夾「上傳」

關鍵tmp不存在,正確的是tmp_name,也 確保該文件夾uploads

if(isset($_POST['upload'])) 
{ 
    $name = $_POST['name']; 
    $album_id = $_POST['album']; 
    $file = $_FILES['file']['name']; 
    $file_type = $_FILES['file']['type']; 
    $file_size = $_FILES['file']['size']; 
    $file_tmp = $_FILES['file']['tmp_name']; //The error is here 
    $random_name = rand(); 

    if(empty($name) || empty($file)) 
    { 
     echo "Please fill all the fields"; 
    } 
    else 
    { 
     move_uploaded_file($file_tmp, 'uploads/'.$random_name.'.jpg');//Error in this line 
     mysqli_query($con,"INSERT INTO `p_photos` (`name`,`album_id`,`url`) VALUES ('$name','$album_id','$random_name.jpg')"); 
     echo 'Photo Uploaded successfully!<br /><br />';   

    } 

} 

瞭解更多關於php file uploads

1

你要找的屬性是tmp_name的值,而不是TMP

+0

謝謝...它的工作! – shaiToro