Hi,
I've got an upload function that should work. Obviously something is wrong. It just reloads the site.
I try to upload a png-file with 12kb and I dont get into the "if($this->upload->do_upload()) {".
Tryed localhost and on onlineserver. What the hack is it? Any hint or help really appreciated!
Controller:
PHP Code:
...
public function mediaupload($media=FALSE)
{
if (!$this->ion_auth->logged_in() || $media==FALSE){redirect(base_url(), 'refresh');}
$public_path = base_url('assets/media/'.strtolower($media));
$config['upload_path'] = dirname($_SERVER['DOCUMENT_ROOT']).'/assets/media/'.strtolower($media);
$config['allowed_types'] = 'gif|jpg|jpeg|png|pdf|mp3|mp4';
$config['max_size'] = '81920';
$config['remove_spaces'] = TRUE; //it will remove all space
$config['encrypt_name'] = TRUE; //it wil encrypte the original file name
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$this->media->saveMedia($public_path);
echo "<pre>"; print_r($this->upload->data()); print_r($this->input->post());echo "</pre>"; exit;
if($this->upload->display_errors())
{ $this->upload->display_errors();
$_SESSION['errormessage'] = $this->upload->display_errors();
$this->session->mark_as_flash('errormessage');
}
//redirect(base_url('media/'.$media), 'refresh');
}
else
{
$id = $this->session->userdata('user_id');
$user = $this->ion_auth->user($id)->row();
$data['title'] = $this->lang->line('mediaupload').' ('.$this->lang->line($media).')';
$data['menu'] = $this->menu();
$data['csrf'] = array('name' => $this->security->get_csrf_token_name(),'hash' => $this->security->get_csrf_hash());
$data['category'] = $media;
$data['typeDropdown'] = $this->typeDropdown();
$data['sub_heading'] = $this->lang->line('please_upload');
$data['username'] = $user->first_name;
$data['view'] = 'media/upload';
if(isset($_SESSION['errormessage'])){$data['errormessage']=$_SESSION['errormessage'];}
$this->load->view('backend',$data);
}
}
...
Model:
PHP Code:
...
public function saveMedia($public_path)
{
$data['file_name'] = $this->upload->data('file_name');
$data['file_type'] = $this->upload->data('file_type');
$data['file_path'] = $this->upload->data('file_path');
$data['full_path'] = $this->upload->data('full_path');
$data['public_path'] = $public_path.'/'.$data['file_name'];
$data['raw_name'] = $this->upload->data('raw_name');
$data['orig_name'] = $this->upload->data('orig_name');
// $data['client_name'] = $this->upload->data('client_name');
$data['file_ext'] = $this->upload->data('file_ext');
$data['file_size'] = $this->upload->data('file_size');
$data['is_image'] = $this->upload->data('is_image');
$data['image_width'] = $this->upload->data('image_width');
$data['image_height'] = $this->upload->data('image_height');
$data['image_type'] = $this->upload->data('image_type');
$data['image_size_str'] = $this->upload->data('image_size_str');
$data['category'] = $this->input->post('category');
$data['user_id'] = $this->session->userdata('user_id');
$data['created_at'] = date('Y-m-d H:i:s',time());
$data['created_by'] = $this->session->userdata('user_id');
$data['updated_by'] = $this->session->userdata('user_id');
if($this->input->post('new_name') && ($this->input->post('new_name') != ''))
{
$filename = $this->input->post('new_name');
if($this->hasExtension($filename))
{ $data['name'] = $filename; }
else{ $data['name'] = $filename . $data['file_ext']; }
}
else{ $data['name'] = $data['orig_name']; }
if($this->input->post('alt') && ($this->input->post('alt') != ''))
{ $data['alt'] = $this->input->post('alt');}
else{ $data['alt'] = $this->cleanAltText($data['orig_name']);}
$data['copyright'] = $this->input->post('copyright');
$data['type'] = $this->input->post('type');
$this->db->insert('media', $data);
$this->save_thumbnail($data['full_path'], $data['raw_name'],'50','50');
if($this->second_size($data['type'])!=FALSE){$this->resize_and_crop($data['type'], $data['file_name'], $this->second_size($data['type']));}
}
...
View:
Code:
...
<?php if(isset($errormessage)&&($errormessage!='')){echo '<div class="alert">'.$errormessage.'</div>';} ?>
<div class="row">
<div class="col-md-12">
<!-- -->
<?php echo form_open_multipart(base_url('media/mediaupload/'.$category));?>
<p>
<label for="category"><?=$this->lang->line('Category')?></label><br />
<?php //if($category != 'image'){$category = substr($category,0,-1);} ?>
<?=$category?> <?=form_hidden('category',$category)?>
</p>
<p>
<label for="type"><?=$this->lang->line('type')?></label><br />
<?=isset($typeDropdown)? $typeDropdown : ''?>
</p>
<p>
<label for="category"><?=$this->lang->line('choose_file')?></label><br />
<input type="file" name="userfile" size="20" />
</p>
<p>
<label for="alt"><?=$this->lang->line('alt_name')?></label><br />
<?=form_input('alt',set_value('alt'),'class="col-md-2"')?><br />
</p>
<p>
<label for="name"><?=$this->lang->line('differing_name')?></label><br />
<?=form_input('new_name',set_value('new_name'),'class="col-md-2" placeholder="'.$this->lang->line('if_needed').'"')?><br />
</p>
<p>
<label for="name"><?=$this->lang->line('copyright')?></label><br />
<?=form_input('copyright',set_value('copyright',''),'class="col-md-2" placeholder="'.$this->lang->line('copyright_owner').'"')?><br />
</p>
<br />
<p>
<input type="submit" value="upload" />
</p>
</form>
...
I tryed "if($this->upload->do_upload('userfile))", but it did not change anything.