2013-10-03 70 views
3

我創建了一個表單,其中一個文件字段位於文件上傳並保存在名爲「att」的文件夾中。 代碼如下:上傳的文件未保存到文件夾中

if($_FILES['file'] != '') 
{ 
    //Settings 

    $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "pdf", "docx","xlsx"); 
    echo $upload_folder = './att/'; //<-- this folder must be writeable by the script 


    $errors =''; 

    //Get the uploaded file information 
    echo $name_of_uploaded_file = basename($_FILES['file']['name']); 

    //get the file extension of the file 
    $type_of_uploaded_file = substr($name_of_uploaded_file, 
          strrpos($name_of_uploaded_file, '.') + 1); 

    $size_of_uploaded_file = $_FILES["file"]["size"]; 

此代碼運行,但該文件未在文件夾中顯示。代碼中有什麼問題

回答

5

請在代碼上添加move_uploaded_file()

的類似:

<?php 
if($_FILES['file'] != '') 
{ 
    //Settings 

    $allowed_extensions = array("jpg", "jpeg", "gif", "bmp", "pdf", "docx","xlsx"); 
    $upload_folder = './att/'; //<-- this folder must be writeable by the script 


    $errors =''; 

    //Get the uploaded file information 
    $name_of_uploaded_file = basename($_FILES['file']['name']); 

    //get the file extension of the file 
    $type_of_uploaded_file = substr($name_of_uploaded_file, 
          strrpos($name_of_uploaded_file, '.') + 1); 

    $size_of_uploaded_file = $_FILES["file"]["size"]; 

    move_uploaded_file($name_of_uploaded_file, $upload_folder);  
    } 

?> 

確保該文件夾ATT可重寫。

5

您只是使用文件細節而不是移動它。移動你sholud使用move_uploaded_file \

eg: 

move_uploaded_file($_FILES['file']['tmp_name'], "PLACE WHERE YOU WANT TO MOVE")