Hướng dẫn php get file name from form - php lấy tên tệp từ biểu mẫu

Tôi có mã sau:

    
       
       

Làm thế nào tôi có thể lấy tên của tệp tôi tải lên để tôi có thể lưu đường dẫn vào cơ sở dữ liệu? Tôi chỉ cần tên của tập tin, không phải toàn bộ đường dẫn. Cảm ơn bạn

hỏi ngày 5 tháng 2 năm 2017 lúc 8:04Feb 5, 2017 at 8:04

AmagramagrAMAGR

591 Huy hiệu vàng1 Huy hiệu bạc4 Huy hiệu đồng1 gold badge1 silver badge4 bronze badges

1

1 câu trả lời

echo $_FILES['fileToUpload']['name'];

Tiếng thét

3291 Huy hiệu vàng3 Huy hiệu bạc13 Huy hiệu đồng1 gold badge3 silver badges13 bronze badges

Đã trả lời ngày 5 tháng 2 năm 2017 lúc 8:06Feb 5, 2017 at 8:06

1

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc$_FILES[“file”][“name”].

    • Bàn luận$_FILES is the by default keyword in PHP to access the details of files that we uploaded.
    • Trong PHP, chúng ta có thể truy cập tên thực tế của tệp mà chúng ta đang tải lên bởi từ khóa $ _FILES [Tệp File] [Tên Tên].file refers to the name which is defined in the “index.html” form in the input of the file.
    • $ _Files là từ khóa mặc định trong PHP để truy cập các chi tiết của các tệp mà chúng tôi đã tải lên.name refers to the actual name of the file.

    Tệp đề cập đến tên được xác định trong biểu mẫu Index index.html trong đầu vào của tệp.

    Tên đề cập đến tên thực tế của tệp.There is a form in the “index.php” file which takes a file as input and then sends it to “file.php” using the POST method and there we can find the name and all other details of the file by using the $_FILES. Always make sure to write the correct name of the file in which you want to send the data. In this, we send the file from “index.php” to “file.php”.

    index.php

    Các

    echo $_FILES['fileToUpload']['name'];
    
    3
    echo $_FILES['fileToUpload']['name'];
    
    4

    echo $_FILES['fileToUpload']['name'];
    
    3
    echo $_FILES['fileToUpload']['name'];
    
    6
    echo $_FILES['fileToUpload']['name'];
    
    7
    echo $_FILES['fileToUpload']['name'];
    
    8
    echo $_FILES['fileToUpload']['name'];
    
    70

    echo $_FILES['fileToUpload']['name'];
    
    3
    echo $_FILES['fileToUpload']['name'];
    
    63 45
    echo $_FILES['fileToUpload']['name'];
    
    83
    echo $_FILES['fileToUpload']['name'];
    
    2

        0

    1

    2

    file.php

    3

        5 678

    echo $_FILES['fileToUpload']['name'];
    
    7____4012

        4 678

    echo $_FILES['fileToUpload']['name'];
    
    7____40    02

            3 678

    echo $_FILES['fileToUpload']['name'];
    
    7____40    92

        

    Bài Viết Liên Quan

    Chủ Đề