结合2个PHP函数

时间:2016-11-07 06:13:11

标签: php

我有2个单独的PHP函数来发布表单数据和上传图像。我想结合这两个功能,这样我就可以获得数据并以相同的形式上传图像。

1

 public function PostStep2()
    {
        $user = $this->check_profile();
        $id = $user['id'];
        if ($_POST)
        {
            $_POST['profile'] = '1';
            $this->model->_update('user_details', $_POST, array("id"=>$id));
            redirect('ProfileStep3');
        }
        else
        {
            err('Something wrong');
        }
    }

2

 public function PostStep3()
    {
        $user = $this->check_profile();
        $id = $user['id'];
        $upload = false;
        for ($i=0; $i < 5; $i++)
        { 
            $file_name = md5(date('YmdHms')).basename($_FILES['img']['name'][$i]);

            $path =  dirname(__FILE__);
            $new_path = strrpos($path, "controller");
            $new_path = substr($path, 0,$new_path-1);
            // $path = $new_path.UPLOAD.'files/'.$file_name;
            $path = $new_path.'/resources/uploads/files/'.$file_name;
            $fileName = strtolower($_FILES['img']['name'][$i]);
            $allowedExts = array('jpg','JPG','jpeg','JPEG','png','PNG');
            $extension = explode(".", $fileName);   
            $extension = end($extension);
            if(in_array($extension, $allowedExts))
            {

1 个答案:

答案 0 :(得分:0)

制作表单将提交的单个文件。

<form action='seperatefile.php' method='post'>

Seperatefile.php,粘贴所有功能并上传参数。

相关问题