开发者

Detect if file was selected using CodeIgniter Input Class

I'm trying to detect if a file was selected using the CodeIgniter input class:

Using the Form Helper to output an upload input in my view:

echo form_upload('image', isset($ad)?$ad['image']:"", 'placeholder="Image" title="Please Choose A File"');

And in my controller:

private function handleUpdate()
{
  $image = $this->input->post('image');

  if($image != none && $image != "")
  {
    $this->handleImageUpload();
  }
}

This of course is a stripped down function, but to illustrate the problem:开发者_运维问答 $image is always coming out empty. What's going on? Using CI 1.7.3


Try this:

if(isset($_FILES['image']['tmp_name'])) {
  do_something();
}


You should use $_FILES with uploading files.

$this->input->post('image') == $_POST['image'];

And make sure you use <form enctype="multipart/form-data">


Thorpe Obazee was right. This worked for me:

if ($this->input->post('img') == $_FILES['img'])
{
    //do upload and resize
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜