0

这是用于上传 swf 字段的代码,但问题是它在 localhost 上工作正常,但在远程服务器上却不行。这是我的控制器

function do_upload()
{
    $pid=$this->input->post('Page_id');
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'swf';
    $config['max_size'] = '1048';
    $config['file_name'] =$pid;

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());

    }
    else{   
        $data=array(
            'id'=>$pid,
            'link'=>base_url()."uploads/",
            'file_name'=>$config['file_name']
        );
        $this->file_upload_model->upload_data($data);
        $this->upload_success();
    }
}

除了将路径和文件名上传到模型中的数据库之外,我没有做任何事情。在此处查看演示

4

3 回答 3

0

尝试这个

$pid=$this->input->post('Page_id');
$config['file_name']        = $pid;
$config['upload_path']      = './uploads/';
$config['allowed_types']    = 'swf';
$config['max_size']         = '1048';
$config['remove_spaces']    = TRUE;

$this->load->library('upload', $config);

if ($this->upload->do_upload()) 
{
    //upload successful
    //do something
} 
else 
{
    $this->session->set_flashdata('error',$this->upload->display_errors());
    redirect('controller/method');

    /*
        In the view file you can echo the error like this 
        echo $this->session->flashdata('error');
    */
}
于 2013-06-23T23:30:57.697 回答
0

您已经在调用中传递了字段名称,do_upload如下所示:

$config = array(
    'allowed_types' => 'jpg|jpeg|swf |png', // pipe seperated file types
    'upload_path' => './uploads/', // should be the root path
    'max_size' => '1048',
    'file_name' => $pid
);

$this->load->library('upload', $config);

if (!$this->upload->do_upload('your_field_name')) {
    // like $this->upload->do_upload($pid)
    $error = array('error' => $this->upload->display_errors());

} else {
    $swf_data = $this->upload->data();

}

希望有意义

于 2013-06-24T07:21:28.627 回答
0

这可能是由于 PHP 服务器版本和它的选项。

1).转到cpanel帐户

2).点击“选择php版本”,在软件部分。

3).点击php选项中的“fileinfo”复选框并保存。

现在您可以完美上传文件了。

于 2017-07-10T18:48:36.253 回答