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
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