【问题标题】:Unlink permission denied on codeigniter在 codeigniter 上取消链接权限被拒绝
【发布时间】:2026-01-13 14:50:01
【问题描述】:

如何删除文件,在代码的输出下方.. 但是这段代码无法从目录中删除文件....

在控制器中

public function delete_by_id()
{
        $id = $this->uri->segment(3);
        $schemeid = $this->uri->segment(4);
        $link = $this->uri->segment(5);

        $tablename = $this->uri->segment(6);
     //unlink code ------------------------------------------>
      $del_image = $this->C_model->getrecordwhere($tablename, array('id' => $id));

      unlink('upload_attachments/'.$del_image->attched_files);


       echo '<pre>';print_r($del_image);die;
   // if($tablename== 'progress')
  //  {

        $where = array('id'=>$id);
        //$where = array('id'=>$id);
        //$where = array('id'=>$id);
        //$where = array('id'=>$id);
        $this->C_model->deleteid($tablename,$where);

        redirect('C2C_contr/'.$link.'/'.$schemeid);

}

输出

遇到了 PHP 错误

严重性:通知

消息:试图获取非对象的属性

文件名:controllers/C2C_contr.php

行号:264

遇到了 PHP 错误

严重性:通知

消息:试图获取非对象的属性

文件名:controllers/C2C_contr.php

行号:267

遇到了 PHP 错误

严重性:警告

消息:取消链接(upload_attachments/):权限被拒绝

文件名:controllers/C2C_contr.php

行号:267

Array
(
    [0] => stdClass Object
        (
            [id] => 111
            [attched_files] => Untitled4.png
            [attched_remarks] => 
        )
)

【问题讨论】:

  • 你在构造函数中加载了这个 C_model 了吗?
  • 公共函数 __construct() { parent::__construct(); $this->load->model('C_model');我已经在构造函数文件中加载了模型是从表中删除但不是从目录路径中删除
  • 使用 $del_image[0] 代替 $del_image 比尝试它。

标签: php codeigniter permissions unlink


【解决方案1】:

你应该更新下面的行 -

unlink('upload_attachments/'.$del_image->attched_files);

//用这个更新

unlink('upload_attachments/'.$del_image[0]['attched_files']);

【讨论】:

    最近更新 更多