dqy92287 2012-07-12 15:20
浏览 28
已采纳

Codeigniter功能跳过

Hi this is a simple question, however I have now stared at it long enough to realise im simply not seeing the error. If anyone can see where this is going wrong I would be very thankful.

public function create()
{
$this->load->model('ticket_model');

if($_POST)
    {
    // validate form
    if($this->_validate())
        {
        // save updates                                 
        foreach($_POST as $key => $value){if(!is_array($value)) $_POST[$key] = htmlspecialchars($value);}

        if ($_POST['subject'] == '')    $body_data['error'][] = "You did not enter a subject.";
        if ($_POST['priority'] == '')   $body_data['error'][] = "You did not select a priority.";
        if ($_POST['status'] == '')     $body_data['error'][] = "You did not select a status.";
        if ($_POST['ipAddress'] == '')  $body_data['error'][] = "You did not enter a ipAddress.";
        if ($_POST['text_area'] == '') $body_data['error'][] = "You did not enter a message.";
        else
            {
            if (filter_var($_POST['ipAddress'], FILTER_VALIDATE_IP,  FILTER_FLAG_IPV4) == FALSE) $body_data['error'][] = "IP Address is not valid IPV4 Address.";
            if (filter_var($_POST['ipAddress'], FILTER_VALIDATE_IP,  FILTER_FLAG_NO_PRIV_RANGE) == FALSE) $body_data['error'][] = "IP Address cannot be from RFC1918 private space.";
            if (filter_var($_POST['ipAddress'], FILTER_VALIDATE_IP,  FILTER_FLAG_NO_RES_RANGE) == FALSE) $body_data['error'][] = "IP Address cannot be from reserved range.";
            }
        if ($_FILES['filename']['name'] != '')
            {
            if ($_FILES['filename']['size'] > '1024000')
                {
                $body_data['error'][]                       = "The file you uploaded is too large.";

                unlink($_FILES['filename']['tmp_name']);

                $body_data['ticket_list']       = $this->ticket_model->list_ticket();
                $body_data['ticket_details']    = $this->ticket_model->get_ticket($ticket_id);
                $body_data['ticket_summary']    = $this->ticket_model->list_ticket_summary($ticket_id);

                $body_data['precan_list']       = $this->ticket_model->list_messages();
                $body_data['users_list']        = $this->ticket_model->list_users();
                $foot_data['accordian_active'] = 5;

                $this->load->view('head',$head_data);
                $this->load->view('sidebar/service',$head_data);
                $this->load->view('ticket/edit',$body_data);
                $this->load->view('foot',$foot_data);
                return;
                }
            else
                {
                //the file is under the specified size. so copy it from temp to import folder and proccess
                $thisFileHumanName      = $_FILES['filename']['name'];
                $thisFileSize           = $_FILES['filename']['size'];
                $thisServerFileName     = strtoupper(uniqid('A'));
                $thisFileType           = $_FILES['filename']['type'];

                $temp_file_location = $this->config->item('rootpath').'/assets/ticketuploads/'.$thisServerFileName;

                if (!move_uploaded_file($_FILES['filename']['tmp_name'], $temp_file_location))
                    {
                    $body_data['error'][]                       = "File could not be moved due to a permissions error.";

                    unlink($_FILES['filename']['tmp_name']);

                    $body_data['ticket_list']       = $this->ticket_model->list_ticket();
                    $body_data['ticket_details']    = $this->ticket_model->get_ticket($ticket_id);
                    $body_data['ticket_summary']    = $this->ticket_model->list_ticket_summary($ticket_id);

                    $body_data['precan_list']       = $this->ticket_model->list_messages();
                    $body_data['users_list']        = $this->ticket_model->list_users();
                    $foot_data['accordian_active'] = 5;

                    $this->load->view('head',$head_data);
                    $this->load->view('sidebar/service',$head_data);
                    $this->load->view('ticket/edit',$body_data);
                    $this->load->view('foot',$foot_data);
                    return;
                    }
                }
            }

        //clean error array
        $body_data['error']                     = array_filter($body_data['error']);

        if ($body_data['error'])
            {
            $body_data['ticket_list']       = $this->ticket_model->list_ticket();
            $body_data['ticket_details']    = $this->ticket_model->get_ticket($ticket_id);
            $body_data['ticket_summary']    = $this->ticket_model->list_ticket_summary($ticket_id);

            $body_data['precan_list']       = $this->ticket_model->list_messages();
            $body_data['users_list']        = $this->ticket_model->list_users();

            unlink($_FILES['filename']['tmp_name']);

            $foot_data['accordian_active'] = 5;

            $this->load->view('head',$head_data);
            $this->load->view('sidebar/service',$head_data);
            $this->load->view('ticket/edit',$body_data);
            $this->load->view('foot',$foot_data);
            return;
            }
        else
            {   

            $_POST['userId'] = $this->session->get_user_id();

            $thisMessageId = $this->ticket_model->save_message($_POST);

            if ($_FILES['filename']['name'] != '')
                {
                //set variables for save
                $_POST['file_path'] = $temp_file_location;
                $_POST['file_name'] = $thisFileHumanName;

                $_POST['file_size'] = $thisFileSize;
                $_POST['file_type'] = $thisFileType;
                $_POST['messageId'] = $thisMessageId;

                $this->ticket_model->save_upload($_POST);
                }
            $this->ticket_model->save_ticket($_POST);

            redirect(base_url().'ticket/');
            return;
            }
        }
    }
$body_data['ticket_list']        = $this->ticket_model->list_ticket();
$body_data['message_list']       = $this->ticket_model->list_message($ticket_id);
$body_data['customer_list']      = $this->ticket_model->list_customers();
$body_data['users_list']         = $this->ticket_model->list_users();

$foot_data['accordian_active'] = 5;
$foot_data['contact_search']   = true;
$this->load->view('head',$head_data);
$this->load->view('sidebar/service',$head_data);
$this->load->view('ticket/create',$body_data);
$this->load->view('foot',$foot_data);
return;
}

This is my code, and everything is going well, except for the section where i save the upload, as nothing seems to be firing the model, even thought there is a file being posted from the from submit and there for the filename being posted is != ''...... e.g

if ($_FILES['filename']['name'] != '')
{
    //set variables for save
    $_POST['file_path'] = $temp_file_location;
    $_POST['file_name'] = $thisFileHumanName;

    $_POST['file_size'] = $thisFileSize;
    $_POST['file_type'] = $thisFileType;
    $_POST['messageId'] = $thisMessageId;

    $this->ticket_model->save_upload($_POST);
}

my apologies if this is silly mistake.

  • 写回答

2条回答 默认 最新

  • dp7311 2012-07-12 15:32
    关注

    Why are you doing it this way? Codeigniter has a built in class for uploading files. You also should be using the input class instead of $_POST. It will make it a lot easier!

    As for your code. You're actually setting the $_POST variable and trying to use that in save_ticket. You can't do that.

    The predefined $_POST variable is used to collect values from a form sent with method="post"

    You're trying to use it the other way around.

    So to make it work, change the $_POST into $something and it should work, but it's still not the way to go.

    //set variables for save
    $something['file_path'] = $temp_file_location;
    $something['file_name'] = $thisFileHumanName;
    
    $something['file_size'] = $thisFileSize;
    $something['file_type'] = $thisFileType;
    $something['messageId'] = $thisMessageId;
    
    $this->ticket_model->save_upload($something);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!