PHP从删除请求获取数据

PHP从删除请求获取数据,php,jquery,codeigniter,Php,Jquery,Codeigniter,我使用jquery插件进行多文件上传。除删除图像外,一切正常。Firebug说它正在向函数发送删除请求。如何从删除请求中获取数据 PHP删除代码: public function deleteImage() { //Get the name in the url $file = $this->uri->segment(3); $r = $this->session->userdata('id_user'); $q=$this->

我使用jquery插件进行多文件上传。除删除图像外,一切正常。Firebug说它正在向函数发送删除请求。如何从删除请求中获取数据

PHP删除代码:

public function deleteImage() {
    //Get the name in the url
        $file = $this->uri->segment(3);
    $r = $this->session->userdata('id_user');
    $q=$this->caffe_model->caffe_get_one_user($r);
        $cff_name= $q->name;
    $cff_id = $q->id_caffe;       

    $w = $this->gallery_model->gallery_get_one_user($gll_id);
    $gll_name = $w->name;
        $success = unlink("./public/img/caffe/$cff_name/$gll_name/" . $file);
        $success_th = unlink("./public/img/caffe/$cff_name/$gll_name/thumbnails/" . $file);

        //info to see if it is doing what it is supposed to 
        $info = new stdClass();
        $info->sucess = $success;
        $info->path = $this->getPath_url_img_upload_folder() . $file;
        $info->file = is_file($this->getPath_img_upload_folder() . $file);
        if (IS_AJAX) {//I don't think it matters if this is set but good for error checking in the console/firebug
            echo json_encode(array($info));
        } else {     //here you will need to decide what you want to show for a successful delete
            var_dump($file);
        }
    }

JS使用的是jQuery文件上传插件:

一般来说,如果删除请求发送了请求体中的数据,您可以使用以下代码读取数据:

$data = file_get_contents("php://input");
根据数据的编码(通常为JSON或表单编码),您可以使用
JSON\u decode
parse\u str
将数据读入可用变量

有关一个简单的示例,请参见,其中作者使用表单编码数据处理
PUT
请求<代码>删除的工作原理类似



但是,在您的情况下,文件名似乎是从请求URL读取的(调用
$this->uri->segment(3);
)。当我查看您的代码时,似乎变量
$gll\u id
没有初始化,并且您没有检查结果对象
$w
和变量
$gll\u name
是否为空。这可能是导致删除失败的原因。使用
ini\u集打开错误记录(“记录错误”,1)
并查看服务器错误日志。如果取消链接失败,错误日志应该包含PHP尝试取消链接的路径-很可能路径不正确。

我丢失了一点(我从未使用过)。如何从单个输入中获取数据?它与文件内容(“php://input)无法使用enctype=“多部分/表单数据”o。O@Sasha我补充了一个解释。