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"];

此代码已运行,但文件未显示在文件夹中。代码有什么问题

4

3 回答 3

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是可重写的。

于 2013-10-03T05:40:49.483 回答
5

您只是使用文件详细信息而不是移动它。为了移动你应该使用move_uploaded_file\

eg: 

move_uploaded_file($_FILES['file']['tmp_name'], "PLACE WHERE YOU WANT TO MOVE")
于 2013-10-03T05:43:20.750 回答
4

你必须使用move_uploaded_file函数。参考这个例子:move_uploaded_file

于 2013-10-03T05:41:33.423 回答