dongpo5239 2015-06-29 18:19
浏览 39

尝试使用cURL删除图像但是将NULL作为响应

I have made a custom status and test if it is 2 and on that basis am trying to delete the main image of a product. At first I didn't know that cURL needs special treatment if working with sessions and I got redirected to the admin login screen. This modification is supposed to go into the file admin/controller/catalog/product (using VQMod of course). Only now I'm getting NULL for response.

if((int) $this->request->post['status'] == 2) {
    if(isset($this->request->post['image'])) {
        $params = array(
            'path' => $this->request->post['image']
        );
        $defaults = array(
            CURLOPT_URL => $this->url->link('common/filemanager/delete', 'token=' . $this->session->data['token'], 'SSL'),
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $params,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_COOKIESESSION => true,
            CURLOPT_COOKIEJAR => 'cookie-jar',
            CURLOPT_COOKIEFILE => '/home/u32807/tmp'
        );
        $ch = curl_init();
        curl_setopt_array($ch, $defaults);
        $ouput = curl_exec($ch);
        if($output === false) {
            echo 'Curl error: ' . curl_error($ch);
            die();
        }
        else {
            var_dump($output);
            die();
        }
    }
}

I tried commenting out CURLOPT_POSTFIELDS and also I tried feeding it an empty array, but still NULL. There must thus be something wrong with the way I have set up the connection but I do not know where to start to debug it. Hewp pweeze! :/ OpenCart version is 1.5.6.4.

  • 写回答

1条回答 默认 最新

  • douji3623 2015-06-29 18:52
    关注

    you need to add one more portion for curl,i.e

    CURLOPT_CUSTOMREQUEST=> 'DELETE',

    check my function for delete:

    public function curl_delete_function($mypath, $json='')

    {

    $url =$this->__url.$mypath;
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL,$url);
    
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $result = curl_exec($ch);
    
    $result = json_decode($result);
    
    curl_close($ch);
    
    
    return $result;
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False