上传简历的上传代码

 /**
     * 会员中心,简历附件上传处理方法
     */
    function attachment_upload() {
        $mdl_attachment = $this->app_current->model('attachment');
        if (!$_POST['attachment']['name']) {
            exit('');
        }
        if (!$_FILES) {
            exit('');
        }
        if ($_FILES['attachment']['error'] != 0) {
            exit('');
        }
        if ($_FILES['attachment']['size'] > 1024 * 1024 * 5) {
            exit('');
        }

        $new_attachment = array(
            'name' => $_POST['attachment']['name'],
            'file_name' => $_FILES['attachment']['name'],
            'resume_id' => $this->resume_basic['resume_id'],
            'member_id' => $this->resume_basic['member_id'],
            'attachment_category' => $_POST['attachment']['attachment_category'],
            );
        $up_file = $_FILES['attachment'];
        $tmp_file = $_FILES['attachment']['tmp_name'];

        $ext = pathinfo($_FILES['attachment']['name'], PATHINFO_EXTENSION);
        $ext = strtolower($ext);
        $allowFileCatgory = array(
            'doc',
            'docx',
            'jpg',
            'jpeg',
            'png',
            'gif',
            'pdf',
            'mp3'
            );
        if (in_array($ext, $allowFileCatgory) === false) {
            exit('');
        }

        $storager = new base_storage_filesystem();
        $storager->f_dir = PUBLIC_DIR . '/files/resume_attachment';
        $storager->base_dir = __ROOT__ . '/public/files/resume_attachment';
        $ident = $storager->save($tmp_file, $url, 'file', '', '.' . $ext);
        if (!$ident) {
            echo '';
            exit;
        }
        $new_attachment['url'] = $url;
        $new_attachment['ident'] = $ident;

        if ($mdl_attachment->save($new_attachment)) {
            echo '';
            exit;
        } else {
            echo '';
            exit;
        }
    }

你可能感兴趣的:(php随记,php扩展)