【问题标题】:Downloading file from ftp in codeigniter 2 using FTP Class使用 FTP 类从 codeigniter 2 中的 ftp 下载文件
【发布时间】:2021-11-24 15:17:01
【问题描述】:

我想使用已经在 CodeIgniter 中的 FTP 类从 FTP 服务器下载一些文件,但是我收到错误 ftp_get() failed to open stream : permission denied 当我调用我的代码时。有人可以帮帮我吗?

这是我的代码

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class C_FTP extends CI_Controller 
{
public function openfile($fileName)
{
    $this->load->library('ftp');
    $config['hostname'] = 'ftp_host';
    $config['username'] = 'ftp_username';
    $config['password'] = 'ftp_password';
    $config['port']     = 'ftp_port';
    $config['debug']    = FALSE;
    $config['passive']  = FALSE;
    $this->ftp->connect($config);
    $this->ftp->download('path/to/folder/', 'local/path', 'auto');
    $this->ftp->close();
}}
?>

我的 ci 版本是:2.2.0

【问题讨论】:

  • 收到 500 错误时需要做的第一件事是检查 PHP 错误日志,然后才能找出真正的错误信息。
  • 提前谢谢你,现在我找到了真正的错误,错误是failed to open stream: permission denied,我已经按照link的步骤进行操作,但不起作用。我得到了差异错误:The system cannot find the file specified 当我将本地路径更改为/tmp 时,我认为这个文件夹只存在于 linux 中,但我使用的是 windows

标签: php codeigniter ftp codeigniter-3 codeigniter-2


【解决方案1】:

我找到了我的问题的解决方案,只需在下载文件之前添加标题 这是我的代码:

之前

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class C_FTP extends CI_Controller 
{
public function openfile($fileName)
{
    $this->load->library('ftp');
    $config['hostname'] = 'ftp_host';
    $config['username'] = 'ftp_username';
    $config['password'] = 'ftp_password';
    $config['port']     = 'ftp_port';
    $config['debug']    = FALSE;
    $config['passive']  = FALSE;
    $this->ftp->connect($config);
    $this->ftp->download('path/to/folder/', 'local/path', 'auto');
    $this->ftp->close();
}}
?>

用这个改变


<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class C_FTP extends CI_Controller 
{
public function openfile($fileName)
{
    $this->load->library('ftp');
    $config['hostname'] = 'ftp_host';
    $config['username'] = 'ftp_username';
    $config['password'] = 'ftp_password';
    $config['port']     = 'ftp_port';
    $config['debug']    = FALSE;
    $config['passive']  = FALSE;
    $this->ftp->connect($config);
    header('Content-type: text/plain');
    header('Content-Disposition: attachment; filename="filename.pdf"');
    $this->ftp->download('path/to/folder/', 'local/path', 'auto');
    $this->ftp->close();
}}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    相关资源
    最近更新 更多