Hướng dẫn unlink image in php - hủy liên kết hình ảnh trong php

0

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 sử dụng Bootstrap phương thức với CodeIgnitter 4. Tôi có thể xóa dữ liệu trong cơ sở dữ liệu nhưng không thể tách hình ảnh. Đây là mã của tôi:

Người mẫu :

public function deleteProduct($id)
{
    $query = $this->db->table('produk')->delete(array('kode' => $id));
    return $query;
}

Người điều khiển:

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}

Tôi muốn xóa hình ảnh trong thư mục nhưng không xóa mặc định.img

Đã hỏi ngày 21 tháng 3 lúc 6:32Mar 21 at 6:32

Hướng dẫn unlink image in php - hủy liên kết hình ảnh trong php

4

Sử dụng đường dẫn thư mục hoàn chỉnh để xóa/truy cập hình ảnh thông qua PHP bằng cách sử dụng $ _server ['Document_root'] để nhận đường dẫn máy chủ.

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}

Đã trả lời ngày 22 tháng 3 lúc 19:53Mar 22 at 19:53

Hướng dẫn unlink image in php - hủy liên kết hình ảnh trong php

FarhanfarhanFarhan

1.4532 huy hiệu vàng15 Huy hiệu bạc20 Huy hiệu đồng2 gold badges15 silver badges20 bronze badges

2

9 năm trước

(Php 4, Php 5, Php 7, Php 8)Deletes a file

Khóc - xóa một tệp

Sự mô tả(string $filename, ?resource $context = null): bool

Hủy liên kết (Chuỗi $filename,? Tài nguyên $context = null): Bool

Thông số

filename

Đường dẫn đến tệp.rmdir() has to be used instead.

Nếu tệp là một Symlink, Symlink sẽ bị xóa. Trên Windows, để xóa Symlink vào một thư mục, RMDIR () phải được sử dụng thay thế.

contextresource.

Một tài nguyên luồng ngữ cảnh.

Trả về giá trịtrue on success or false on failure.

Trả về true khi thành công hoặc false về thất bại.

Thay đổiKhóc - xóa một tệp
7.3.0 Sự mô tảunlink() files with handles in use, while formerly that would fail. However, it is still not possible to re-create the unlinked file, until all handles to it have been closed.

Hủy liên kết (Chuỗi $filename,? Tài nguyên $context = null): Bool

Thông sốunlink() usage

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
0

filename

  • Đường dẫn đến tệp.

Nếu tệp là một Symlink, Symlink sẽ bị xóa. Trên Windows, để xóa Symlink vào một thư mục, RMDIR () phải được sử dụng thay thế.

context

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
1

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
2

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

Một tài nguyên luồng ngữ cảnh.

11 năm trước

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
4

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
5

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
6

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
7

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
8

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

Trả về giá trị

8 năm trước

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
0

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
1

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

Federico tại Poisonfx dot com ¶

11 năm trước

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
4

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

Chris tại Vibenewmedia dot com

18 năm trước

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
6

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
7

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

PD ¶

14 năm trước

 public function delete(){
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink($_SERVER['DOCUMENT_ROOT'].'/imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
9

$filename0

$filename1

$filename2

$filename3

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

gotdalife tại gmail dot com

14 năm trước

$filename5

$filename6

$filename7

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

gotdalife tại gmail dot com

8 năm trước

$filename9

Eric ¶

Divivent76+Spam tại Gmail Dot Com ¶

$context0

2 tháng trước đây

llmll tại gmx dot de ¶

$context1

$context2

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

7 năm trước

Keatran ¶

$context4

$context5

 public function delete()
{
    $model = new produkModel();
    $id = $this->request->getPost('kode');
    $produk = $this->produkModel->find($id);
    
    if ($produk['gambar'] != 'default.png') {
      
        unlink('imgproduk/' . $produk['gambar']);
    }
    $model->deleteProduct($id);
    return redirect()->to('/Tabel_Produk');
}
3

2 năm trước

Alex, Marrch CA ' tại ¶

$context7