Page 1 of 1
PHP Class Function and Public Variable Help
Posted: Wed Dec 29, 2004 12:08 pm
by Bon Bon
I have not been here for a while but I have been busy with college so I have not really had the time to check out this place.
I have just swtiched from Apcache to IIS so that I could use ASP.NET with applications that I plan to create in the future.
Getting to the point, I am writing a class in PHP and it does not seem to work properly, I do not know if it is my programming or to do with IIS.
Code: Select all
function OpenConnection () {
$Connection = ftp_connect($IpAddress);
ftp_login($Connection,$Username, $Password);
}
function ListFiles ($Connection) {
ftp_pwd($Connection);
}
function CloseConnection ($Connection) {
ftp_close($Connection);
}
The problem is, no matter if I use $this->Connection for ListFiles() or CloseConnection() I get an error message saying:
Warning: ftp_pwd() expects parameter 1 to be resource, null given in
ftp_class.php
I want to be able to use variables set in the first function in the next two functions but I cannot seem to do this. I would be greatful for any help.
Posted: Wed Dec 29, 2004 12:19 pm
by Joe
It says in the manual that ftp_pwd returns the current directory or FALSE on error. Perhaps false is infact being returned.
Posted: Wed Dec 29, 2004 12:20 pm
by Joe
Also, if that is supposed to be a class then you are going the wrong way about defining your functions.
Posted: Wed Dec 29, 2004 12:21 pm
by feyd
Code: Select all
class whatever
{
var $Connection;
function OpenConnection()
{
$this->$Connection = ftp_connect(...);
...
}
function ListFiles()
{
ftp_pwd( $this->Connection );
}
}
Posted: Wed Dec 29, 2004 12:28 pm
by Bon Bon
I tried that before and it never worked, it is still not working. I presume this is an error with IIS or something because previous work with classes which were programmed just like you have typed there seemed to work. The help is much appricated.
This is the full script so far:
Code: Select all
<?php
/**
* +-------------------------------------------------------------------------------------+
* Ftprotocol
* +-------------------------------------------------------------------------------------+
* This script has a public domain license
* +-------------------------------------------------------------------------------------+
* This script comes as-is and may harm your computer. By using this script you
* are liable for the outcome
* +-------------------------------------------------------------------------------------+
* Author(s): Matthew "Bon Bon" Bonner
* +-------------------------------------------------------------------------------------+
* Variables not in a class should have names with words separated by underscores
* and variables in a class should have words with camel-type naming
* +-------------------------------------------------------------------------------------+
*/
class FtpConnection {
var $Connection;
function OpenConnection () {
$this->$Connection = ftp_connect('80.4.61.62');
ftp_login($Connection, 'Anonymous', '********');
}
function ListFiles () {
ftp_pwd($this->Connection);
}
function CloseConnection () {
ftp_close($this->Connection);
}
}
?>
and this is the full error I am getting:
Warning: ftp_login() expects parameter 1 to be resource, null given in
C:\Documents and Settings\All Users\Documents\Web Server\includes\ftp_class.php on line
24
Warning: ftp_pwd() expects parameter 1 to be resource, null given in
C:\Documents and Settings\All Users\Documents\Web Server\includes\ftp_class.php on line
28
Warning: ftp_close() expects parameter 1 to be resource, null given in
C:\Documents and Settings\All Users\Documents\Web Server\includes\ftp_class.php on line
32
Posted: Wed Dec 29, 2004 12:32 pm
by feyd
your call to ftp_login is wrong... you need to use the correct variable... (I accidently made a slight boo-boo in my posted code.. the $ before the first Connection)
Posted: Wed Dec 29, 2004 12:39 pm
by Bon Bon
I still get errors, even when I use:
Code: Select all
$this->Connection = ftp_connect('80.4.61.62');
The errors I am now getting are:
Warning: ftp_login() expects parameter 1 to be resource, null given in
C:\Documents and Settings\All Users\Documents\Web Server\includes\ftp_class.php on line
24
Warning: ftp_pwd(): Please log in with USER and PASS first. in
C:\Documents and Settings\All Users\Documents\Web Server\includes\ftp_class.php on line
28
Posted: Wed Dec 29, 2004 12:40 pm
by feyd
Code: Select all
ftp_login($this->Connection, 'Anonymous', '********');
Posted: Wed Dec 29, 2004 12:41 pm
by Bon Bon
Ah ha, right. I have got it working now. I see what I was doing wrong and I understand what you were talking about now. Thanks.
Code: Select all
<?php
/**
* +-------------------------------------------------------------------------------------+
* Ftprotocol
* +-------------------------------------------------------------------------------------+
* This script has a public domain license
* +-------------------------------------------------------------------------------------+
* This script comes as-is and may harm your computer. By using this script you
* are liable for the outcome
* +-------------------------------------------------------------------------------------+
* Author(s): Matthew "Bon Bon" Bonner
* +-------------------------------------------------------------------------------------+
* Variables not in a class should have names with words separated by underscores
* and variables in a class should have words with camel-type naming
* +-------------------------------------------------------------------------------------+
*/
class FtpConnection {
var $Connection;
function OpenConnection () {
$this->Connection = ftp_connect('80.4.61.62');
ftp_login($this->Connection, 'Anonymous', '*********');
}
function ListFiles () {
ftp_pwd($this->Connection);
}
function CloseConnection () {
ftp_close($this->Connection);
}
}
?>
Posted: Wed Dec 29, 2004 12:47 pm
by Bon Bon
I am trying to work out what is wrong with my IIS because it is stopping me from using PhpMyAdmin due to a problem related to classes and variables which I presume will be caused by the same problem. If I cannot get my IIS working properly I will get my mate from Microsoft to come and have a look at it for me. For now I am glad that I can allow FTP connections because then I can send my work to my house from college without any messing about. Once again thanks.
Posted: Wed Dec 29, 2004 12:48 pm
by Joe
IIS is a pain in the ass!
Posted: Wed Dec 29, 2004 12:49 pm
by Bon Bon
You deleted your last post and it makes me look even more stupid now then I did before I had to ask for help.
IIS makes me lose sleep at night.
Posted: Wed Dec 29, 2004 1:01 pm
by Joe
Nobody said your stupid

and yeah I have to agree with you mate IIS does make you loose sleep at night.