[eluser]mabright[/eluser]
I am almost done with my internal message system but I am stuck on attaching a file to a message. I have a view called compose, where a user composes a internal message. I am using the JQuery Mutile File upload java-script and this works fine, I can see the files on the screen as I add them.
In my messages controller, method compose calls methos "send" when the message is submitted. From here I call do_upload and then send the message but no file is uploaded to my server and no error message is returned.
Form
Code:
<div id="mc_container">
<form method="post" action="<?php echo current_url().'/send'; ?>" enctype="multipart/form-data" />
<div id="msg_compose">
<ol>
<li>
<?php echo validation_errors(); ?>
<p class="error_text"><?php echo $this->session->flashdata('message'); ?></p>
</li>
<li>
<label class="label_required">From:</label>
<p><?php echo $this->session->userdata('username'); ?></p>
</li>
<li>
<label class="label_required">To:
<?php
$atts = array('width' => '500',
'height' => '400',
'scrollbars' => 'no',
'status' => 'no',
'resizable' => 'no',
'screenx' => '0',
'screeny' => '0');
echo anchor_popup('member/messages/member_search/recipients', img('images/icons/magnifier.png'), $atts);
?>
</label>
<input class="msg_compose_input" type="text" name="input_recipients" id="input_recipients" value="<?php echo set_value('input_recipients[]'); ?>" tabindex="1"/>
<?php echo form_error('input_recipients'); ?>
</li>
<li>
<label class="label_required">CC:
<?php
$atts = array('width' => '500',
'height' => '400',
'scrollbars' => 'no',
'status' => 'no',
'resizable' => 'no',
'screenx' => '0',
'screeny' => '0');
echo anchor_popup('member/messages/member_search/cc', img('images/icons/magnifier.png'), $atts);
?>
</label>
<input class="msg_compose_input" type="text" name="input_cc" id="input_cc" value="<?php echo set_value('input_cc[]'); ?>" tabindex="2"/>
</li>
<li>
<label class="label_required">Subject:</label>
<input class="msg_compose_input" type="text" name="input_msg_subject" id="input_msg_subject" value="<?php echo set_value('input_subject'); ?>" tabindex="3"/>
</li>
<li>
<label class="label_required"><?php echo img('images/attach.png'); ?></label>
</li>
<li>
<textarea class="msg_compose_textarea" name="input_msg_body" id="input_msg_body" TABINDEX="4"><?php echo set_value('input_msg_body'); ?></textarea>
</li>
<li>
<p class="msg_field_note">Allowed file types: gif, jpg. Max Size: 2M. 3 Files Max.</p>
<label class="label_required">Attachment:</label>
<input type="file" name="msgfile[]" class="multi" maxlength="3" accept="gif|jpg" tabindex="5"/>
</li>
<li>
<label class="nolabel">.</label>
<input name="send_msg" class="button" type="submit" value="Send Message" />
</li>
</ol>
</div>
</form>
</div>
<?php
/* End of file message_compose_view.php */
Controller method send()
Code:
public function compose($action = '')
{
$msg_data = array('inbox_count' => $this->inbox_count,
'sent_count' => $this->sent_count,
'trash_count' => $this->trash_count);
if(!$action || $this->form_validation->run() == FALSE)
{
$data['column_main'] = $this->load->view('member/message_compose_view', $msg_data, TRUE);
$this->_display('',$data);
}
elseif(strtoupper($action) == 'SEND')
{
$this->send();
}
elseif(strtoupper($action) == 'PREVIEW')
{
$this->preview();
}
}
private function send()
{
$has_attachment = '';
$msg_data = array('inbox_count' => $this->inbox_count,
'sent_count' => $this->sent_count,
'trash_count' => $this->trash_count);
//Upload attachment file(s) to server
$this->load->library('upload');
$this->upload->do_upload();
......send message, link to uploaded files, etc.
}