出于安全原因,escapeshellarg() 已被禁用.添加了“@”仍然不起作用


escapeshellarg() has been disabled for security reasons. Added '@' still not working

我在社区中搜索并发现添加:

  $cmd = 'file --brief --mime ' . @escapeshellarg($file['tmp_name']) . 

可能会解决问题,但事实并非如此。

我正在尝试在Codeginter PHP中上传文件。

开发了一个在本地计算机上运行良好的应用程序,我能够上传文件,但后来我将其移动到实时服务器。

现在我收到一个错误:

遇到 PHP 错误

Severity: Warning
Message: escapeshellarg() has been disabled for security reasons
Filename: libraries/Upload.php
Line Number: 1039
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/primeasp/public_html/bizlnps_prov/system/core/Exceptions.php:186)
Filename: helpers/url_helper.php
Line Number: 543

但事实并非如此,所以我在这里发布了。

为什么我会收到此错误?我将如何解决它?

法典:

function do_upload()
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = '*';
    $this->load->library('upload', $config);
    $this->upload->initialize($config);

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('customer/upload/upload_ini', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
        $id = $this->session->userdata('id');
        foreach ($data as  $row) 
        {
            $file_name = $row['file_name'];
            $file_path = $row['file_path'];
        }
        $site = $this->session->userdata('site');
             $insert_data = array(
                'customer_id' => $id,
                'base_ini_filename' => $file_name,
                'file_path'=>$file_path,
                'site_key'=>$site
                 );
            $this->db->insert('base_ini', $insert_data);
            redirect('customer/upload_ini/index');
            $this->data['subview'] = 'customer/upload/upload_success';
            $this->load->view('customer/_layout_main', $this->data);
    }

主机已禁用escapeshellarg功能。在函数前面使用 @ 可以抑制错误,这并不意味着函数在添加后会实际工作。

要么

找到允许此功能的主机,要么购买专用资源,例如VPS/专用服务器,您可以在其中安装自己的PHP版本并选择要启用的功能。

escapeshellarg() 在字符串周围添加单引号,并对任何现有的单引号进行引号/转义,允许您将字符串直接传递给 shell 函数并将其视为单个安全参数。

这很简单,可以自己做,因为它在您的主机上被阻止了。

$cmd = "file --brief --mime '" . str_replace("'","''",$file['tmp_name']). "'";

小提琴