在php ci框架中上传文件既不显示错误也不显示结果

时间:2015-08-20 11:33:22

标签: php codeigniter

我看过很多视频并从CI用户指南中获取参考但是无法找出错误。当从表单提交文件时,它会向程序流发送下面的uploadImage()方法。请帮我解决问题。 谢谢

我的代码:

     public function uploadImage()
    {
        $config['upload_path'] = './files/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $this->load->library('upload');
        $this->upload->initialize($config);

        if(!$this->upload->do_upload())
        {
        $this->load->view('upload');
        }
        else
        {
        $this->upload->display_errors();
        }

    }

2 个答案:

答案 0 :(得分:0)

我不知道你打算做什么,因为下面的PLZ可能有所帮助......

// open input
$reader = new XMLReader();
$reader->open('php://stdin');

// open output
$output = fopen('php://stdout', 'w');
fputcsv($output, ['id', 'name']);

$xmlns = [
  'a' => 'http://www.abc-example.com'
];

// prepare DOM
$dom   = new DOMDocument;
$xpath = new DOMXpath($dom);
foreach ($xmlns as $prefix => $namespaceURI) {
  $xpath->registerNamespace($prefix, $namespaceURI);
}

// look for the first record element
while (
  $reader->read() && 
  (
    $reader->localName !== 'ABCRecord' || 
    $reader->namespaceURI !== $xmlns['a']
  )
) {
  continue;
}

// while you have an record element
while ($reader->localName === 'ABCRecord') {
  if ($reader->namespaceURI === 'http://www.abc-example.com') {
    // expand record element node
    $node = $reader->expand($dom);
    // fetch data and write it to output
    fputcsv(
      $output, 
      [
        $xpath->evaluate('string(a:ABC)', $node),
        $xpath->evaluate('string(a:Entity/a:LegalName)', $node)
      ]
    );
  }

  // move to the next record sibling
  $reader->next('ABCRecord');
} 

//以下内容可能有助于调试

id,name
5967007LIEEXZX4LPK21,"REGISTERENHETEN I Bornheim"
5967007LIE45ZX4MHC90,"SUNNDAL HOSTBANK"

答案 1 :(得分:0)

我认为这是一个语法错误,请注意箭头。

public function uploadImage()
{
    $config['upload_path'] = './files/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload');
    $this->upload->initialize($config);

    if($this->upload->do_upload('YOUR_FILE_INPUT_NAME'))  <=========== HERE
    {
     $this->load->view('upload');
    }
    else
    {
     $this->upload->display_errors();
    }
}

基本上,你告诉它在上传成功时加载视图,否则如果操作失败则显示错误。