Hướng dẫn how can i delete upload file in php? - Làm cách nào để xóa tệp tải lên trong php?

2

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi đang cố xóa một bức ảnh khỏi thư mục tải lên khi tôi nhấn xóa tất cả các bản ghi bị xóa ngoại trừ ảnh trong thư mục tải lên ở đây là xóa tôi, cách tôi mã đoạn trích để xóa khỏi thư mục tải lên

//trigger <?php echo '<td><a href="delete.php?staff_id=' . $row['staff_id'] . '"><input type="button" title="confirmDelete(event)" value="delete">'; // check if the 'staff_id' variable is set in URL, and check that it is valid if (isset($_GET['staff_id']) && is_numeric($_GET['staff_id'])) { // get staff_id value $staff_id = $_GET['staff_id']; // delete the entry $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id") or die(mysql_error()); }

Parixit

3.7893 huy hiệu vàng38 Huy hiệu bạc60 Huy hiệu đồng3 gold badges38 silver badges60 bronze badges

hỏi ngày 27 tháng 9 năm 2013 lúc 2:27Sep 27, 2013 at 2:27

4

Trong tập lệnh delete.php của bạn, bạn sẽ cần một dòng như thế này:

unlink( "path_to_your_upload_directory/".$staff_id.".jpg" );

Nếu bạn có các tiện ích mở rộng tệp khác nhau: Một cách để đạt được nó là trước tiên là lưu tên tệp với phần mở rộng trong bảng cơ sở dữ liệu thích hợp khi người dùng/nhân viên tải lên tệp. Lấy giống nhau và sử dụng nó khi xóa tệp:

$filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension );

Đã trả lời ngày 27 tháng 9 năm 2013 lúc 3:13Sep 27, 2013 at 3:13

UoursuaursUours

2.5071 Huy hiệu vàng16 Huy hiệu bạc21 Huy hiệu đồng1 gold badge16 silver badges21 bronze badges

1

Hàm hủy liên kết () trong PHP. Bạn phải cung cấp đường dẫn đầy đủ đến tệp đó trong tham số.

Lưu ý: Không cho đường dẫn //.

Đã trả lời ngày 27 tháng 9 năm 2013 lúc 7:59Sep 27, 2013 at 7:59

ParixitparixitParixit

3.7893 huy hiệu vàng38 Huy hiệu bạc60 Huy hiệu đồng3 gold badges38 silver badges60 bronze badges

hỏi ngày 27 tháng 9 năm 2013 lúc 2:27

Trong tập lệnh delete.php của bạn, bạn sẽ cần một dòng như thế này:Sep 27, 2013 at 6:26

if(isset($_GET['staff_id'])&&is_numeric($_GET['staff_id'])) { $Staff_Id = mysql_real_escape_string($_GET['staff_id']); if($Staff_Id != '.' || $Staff_Id != '..') { $extension = '.jpg'; if(unlink('uploads/'.$Staff_Id.$extension)) { $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id")or die(mysql_error()); } } }

Đã trả lời ngày 27 tháng 9 năm 2013 lúc 3:13Sep 27, 2013 at 3:13

user2801966user2801966user2801966

Uoursuaurs3 silver badges10 bronze badges

7

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

    ĐọcSyntax:

    unlink( $filename, $context );

    Bàn luậnProgram 1: This program uses unlink() function to remove file from directory. Suppose there is a file named as “gfg.txt” 

    Để xóa một tệp bằng cách sử dụng PHP rất dễ dàng. Xóa một tệp có nghĩa là xóa hoàn toàn một tệp khỏi thư mục để tệp không còn tồn tại. PHP có hàm hủy liên kết () cho phép xóa một tệp. Hàm Php Unlink () có hai tham số $ FileName và $ bối cảnh. Cú pháp:

    <?php

    Dưới đây các chương trình minh họa cách tiếp cận trên: Chương trình 1: Chương trình này sử dụng hàm Unlink () để xóa tệp khỏi thư mục. Giả sử có một tệp có tên là GFG.TXT, & NBSP;

    PHP

    unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 0 unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 1

    $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 1

    unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 2 unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 3unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 015

    unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 6unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 7 unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 8unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 0 $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 0

    $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 1

    if(isset($_GET['staff_id'])&&is_numeric($_GET['staff_id'])) { $Staff_Id = mysql_real_escape_string($_GET['staff_id']); if($Staff_Id != '.' || $Staff_Id != '..') { $extension = '.jpg'; if(unlink('uploads/'.$Staff_Id.$extension)) { $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id")or die(mysql_error()); } } } 0

    Output:

    gfg.txt has been deleted

    $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 2 $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 3 This program uses unlink() function to delete a file from folder after using some operation. 

    Để xóa một tệp bằng cách sử dụng PHP rất dễ dàng. Xóa một tệp có nghĩa là xóa hoàn toàn một tệp khỏi thư mục để tệp không còn tồn tại. PHP có hàm hủy liên kết () cho phép xóa một tệp. Hàm Php Unlink () có hai tham số $ FileName và $ bối cảnh. Cú pháp:

    <?php

    Dưới đây các chương trình minh họa cách tiếp cận trên: Chương trình 1: Chương trình này sử dụng hàm Unlink () để xóa tệp khỏi thư mục. Giả sử có một tệp có tên là GFG.TXT, & NBSP;

    unlink( $filename, $context );0unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 0if(isset($_GET['staff_id'])&&is_numeric($_GET['staff_id'])) { $Staff_Id = mysql_real_escape_string($_GET['staff_id']); if($Staff_Id != '.' || $Staff_Id != '..') { $extension = '.jpg'; if(unlink('uploads/'.$Staff_Id.$extension)) { $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id")or die(mysql_error()); } } } 7unlink( $filename, $context );3if(isset($_GET['staff_id'])&&is_numeric($_GET['staff_id'])) { $Staff_Id = mysql_real_escape_string($_GET['staff_id']); if($Staff_Id != '.' || $Staff_Id != '..') { $extension = '.jpg'; if(unlink('uploads/'.$Staff_Id.$extension)) { $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id")or die(mysql_error()); } } } 9

    unlink( $filename, $context );5unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 0unlink( $filename, $context );7

    PHP

    unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 0 unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 1

    $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 1

    unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 2 unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 3unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 015

    unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 6unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 7 unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 8unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 0 $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 0

    $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 1

    if(isset($_GET['staff_id'])&&is_numeric($_GET['staff_id'])) { $Staff_Id = mysql_real_escape_string($_GET['staff_id']); if($Staff_Id != '.' || $Staff_Id != '..') { $extension = '.jpg'; if(unlink('uploads/'.$Staff_Id.$extension)) { $result = mysql_query("DELETE FROM development WHERE staff_id=$staff_id")or die(mysql_error()); } } } 0

    Output:

    Warning: unlink() expects parameter 1 to be a valid path, resource given in C:\xampp\htdocs\server.php on line 12 Resource id #3 cannot be deleted due to an error

    $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 2 $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 3 If the file does not exist then it will display an error.

    unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 6unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 7 unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 8unlink( "path_to_your_upload_directory/".$staff_id.".jpg" ); 0 $filename_with_extension = 'retrieve this from database table where it is stored'; unlink( "path_to_your_upload_directory/".$filename_with_extension ); 8


    Làm thế nào để bạn xóa các tài liệu đã tải lên?

    Xóa một tài liệu tải lên..
    Mở trang tải lên tài liệu của bạn ..
    Nhấp hoặc nhấn vào biểu tượng có thể vào bên phải tài liệu của bạn. ....
    Xác nhận xóa bằng cách nhấp hoặc nhấn vào tùy chọn Xóa Xóa ..
    Một tin nhắn sẽ xuất hiện trên màn hình xác nhận tài liệu đã bị xóa ..

    Làm cách nào để xóa tất cả các tệp trong một thư mục trong PHP?

    Lặp lại danh sách các tập tin. Kiểm tra xem tên của các tập tin có hợp lệ không. Xóa tệp bằng phương thức Unlink () ...
    Tạo danh sách các tệp bằng phương thức glob () ..
    Lọc danh sách bằng các phương thức Array_Filter () hoặc Array_merge () ..
    Ánh xạ phương thức Danh sách để hủy liên kết () bằng phương thức Array_Map () ..

    Làm cách nào để xóa một tệp trong HTML?

    Nhấp chuột phải vào các tệp một lần nữa và chọn "Xóa."Nhấp vào "Có" để xác nhận xóa.Lặp lại quy trình này để xóa tất cả các tệp chỉ đọc HTML trên máy tính.. Repeat this process to delete all the HTML read-only files on the computer.

    Chức năng nào được sử dụng để xóa một tệp?

    Hàm xóa trong C/C ++ có thể được sử dụng để xóa một tệp.Hàm trả về 0 nếu các tệp bị xóa thành công, các tệp khác trả về giá trị khác không.Sử dụng hàm Remove () trong C, chúng ta có thể viết một chương trình có thể tự phá hủy sau khi nó được biên dịch và thực thi.remove function in C/C++ can be used to delete a file. The function returns 0 if files is deleted successfully, other returns a non-zero value. Using remove() function in C, we can write a program which can destroy itself after it is compiled and executed.

    Chủ đề