Jump to content

Having a hard time including a PHP class


Recommended Posts

Hello all, this is what I have for a class that I'm working on.

<?php

include_once "../FTP/FTP.php";

/**
* Fax.php:
* This is a utility to fax documents using FTP.
*/
class Lifespan_Fax_Fax extends Zend_View_Helper_Abstract {
    /**
     * This is where we will keep the FTP connection object alive.
     * @var object FTP
     */
    private $ftpConnection;
    
    public function __construct($server = '', $port = '', $username = '',
        $password = '') {
        
        if (('' == $server) || ('' == $port) || ('' == $username) ||
            ('' == $password)) {
            $server   = 'ftpofdoom.org';
            $port     = '10081';
            $username = 'cookies';
            $password = 'chips';
        }
        
        $this->ftpConnection = new FTP($server, $port, $username, $password);
    }
    
    public function send($directory, $filename, $data) {
        $this->ftpConnection->writeToFTPServer($directory, $filename, $data);
    }
}

I'm doing this in Zend Studio 9 (our dev environment) and I call new FTP, it says that the FTP class is not found.  The class exists in one directory up and in the FTP directory there.  Basically this:

library/
  FTP/
    FTP.php
  Fax/
    Fax.php

What am I doing wrong?

 

P.S.: No, that is not the legit URL, username or password.  You can go there, but I have no idea what you will see :) .

Link to comment
Share on other sites

The FTP class should be included with a path relative to the file including the Fax file.

 

In other words if you have a file structure as:

 

Library/

    MyFoo/

        Foo.php

    MyBar/

        Bar.php

Test.php

 

Bar.php

 

<?php

include '../MyFoo/Foo.php';

?>

 

Test.php

 

<?php

include 'Library/MyBar/Bar.php';

?>

 

An error will occur because Test.php will go back a directory into LibraryParent/ then try to find a directory called MyFoo/ in there so the overal relative link Test.php searches for via Bar.php is LibraryParent/MyFoo/Foo.php which doesn't exist.

 

That's why your error is cropping up.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.