【问题标题】:upload using curl php POST parameter is missing使用 curl php POST 参数上传丢失
【发布时间】:2016-09-21 04:37:42
【问题描述】:

您好,我想在 codeigniter 中使用 curl 将文件上传到服务器 我在视图中设置表单并传递给控制器​​并在控制器中使用 curl 上传 但它显示错误

缺少 POST 参数 issue_identifier 不知道是什么问题造成的

这是我的控制器

  $issue_name = $this->input->post('issue_name');
  $issue_tagline = $this->input->post('issue_tagline');
  $issue_description = $this->input->post('issue_description');
  $issue_publish_on = $this->input->post('issue_publish_on');
  $issue_file = $this->input->post('issue_file');
  $issue_id = $this->input->post('issue_id');

$data2=array(
  'imgdetail'=>$imgdetail ,
  'username' =>$session_data['username'],
  'appname'=> $this->appname,
  'mode'=> $this->mode,
  'appidentifier'=> $this->appidentifier,
  'name' => $name,
  'productid' => $productid,
  'status'=>$status,
  'description'=>$description,
  'issue_name' => $issue_name,
  'issue_tagline' => $issue_tagline,
  'issue_description' => $issue_description,
  'issue_file' => $issue_file,
 ); 

$this->load->helper('form');
$this->load->view('issue_detail',$data2);


  echo '<pre>' .var_dump($issue_name).'</pre>';
  echo '<pre>' .var_dump($productid).'</pre>';
  echo '<pre>' .var_dump($issue_id).'</pre>';

  $target_url = 'https://platform.twixlmedia.com/admin-api/1/upload';

  $file_name_with_full_path = realpath($issue_file);
  $post3 = array(
'admin_api_key'    => 'da06751194bc18cc60xxxxxxxxxxxx',
'app_key'          => 'bd7cf04226c58723cac4xxxxxxxxx',
'issue_identifier' => $issue_id,
'issue_file'       =>'@' . realpath($issue_file),
'issue_name'       => $issue_name
  );

$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_URL, 'https://platform.twixlmedia.com/admin-api/1/upload');
curl_setopt($ch3, CURLOPT_POST, 1);
curl_setopt($ch3, CURLOPT_POSTFIELDS, http_build_query($post3));
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
$result3 = curl_exec($ch3);
curl_close ($ch3);
echo $result3;

这是我的观点:

            <form class="editissueform" action="home/detail_issue" method="post" enctype="multipart/form-data">
            <label for="name">Name:</label>
            <input type="text" name="issue_name"><br>
            <label for="tagline">Tagline:</label>
            <input type="text" name="issue_tagline"><br>
            <label type"description">Description:</label>
            <input type="text" name="issue_description"><br>
            <label type"publishdate">Publish Date:</label>
            <input type="text" name="issue_publish_on"><br>

        </div>
        <h4>Upload Publication</h4>
        <div class="issuedit">

            <input type="file" name="issue_file" size="40" />
            <h7>Please Upload using pdf file format</h7>

        </div>
        <br>
        <br>
        <input type="submit" name="submit" value="Save">
        </form>  

感谢您的帮助

【问题讨论】:

    标签: php html codeigniter curl


    【解决方案1】:

    看起来您的另一端正在向您发送错误,并且该错误似乎意味着您没有在 POST 请求中发布“issue_id”。

    $issue_id = $this->input->post('issue_id');
    

    这就是您获取“issue_id”的方式,但是当我查看您的表单时,我看不到该字段,这意味着它将为空或为空。

    为您的 curl 请求提供另一端理解的有效“issue_id”,我认为您已完成。

    【讨论】:

    • 哦,好吧,我的错.. 在我上传表单后我想回到我的问题 ID 页面(localhost/ideocreative/home/detail_issue/issue_detail/25237)我该怎么做?现在,在我提交按钮后,它会自动重定向到 localhost/ideocreative/home/detail_issue/issue_detail 而没有问题 ID 号
    • 我想你从你的 POST 请求中得到了一些数据。也许您可以使用该数据将您的用户重定向到正确的页面。在Codeigniter中你可以使用redirect函数来执行重定向,redirect('/ideocreative/home/detail_issue/issue_detail/' . $issue_id, 'location', 301);
    • 重定向不起作用它会生成双 url (/ideocreative/home/detail_issue/issue_detail/home/detail_issue/issue_detail/)
    • 'location'和301在重定向中的作用是什么?实际上我希望在发布请求后将其加载回特定的问题 ID 页面(/issue_detail/25237)我希望你理解我的意思
    • 你应该阅读你正在使用的框架的文档:ellislab.com/codeigniter/user-guide/helpers/url_helper.html
    猜你喜欢
    • 1970-01-01
    • 2014-11-17
    • 2018-05-08
    • 1970-01-01
    • 2013-08-07
    • 2015-12-18
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    相关资源
    最近更新 更多