codeigniter文件未在远程服务器上上传

时间:2013-06-23 18:35:27

标签: php mysql codeigniter file-upload

这是swf fiel上传的代码,但问题是它在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();
    }
}

除了将路径和文件名上传到模型中的数据库之外,我还没有做任何事情。请参阅演示here

3 个答案:

答案 0 :(得分: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');
    */
}

答案 1 :(得分: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();

}

希望它有意义

答案 2 :(得分:0)

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

1)。转到cpanel帐户

2)。点击软件部分中的“选择php版本”。

3)。在php选项中输入“fileinfo”chexbox并保存。

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

相关问题