Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 11-12-2009, 11:55 PM   #1
Edmund Lee
War Room Member
 
edmltw's Avatar
 
Join Date: Jul 2009
Location: Singapore
Posts: 624
Blog Entries: 2
Thanks: 124
Thanked 91 Times in 57 Posts
Social Networking View Member's Myspace Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to edmltw
Default Problem here need help!

Hi professional coders..

I have been tinkering around with php scripts for an online ebook store..

I did everything according to the instructions, however when I tried to access the "./admin" of the site, this appeared.

Fatal error: Cannot re-assign $this in /home/CENSORED4Privacy/public_html/admin/includes/classes/upload.php on line 24

is that got to do some php part which I left out?

Help please!

Ed

edmltw is offline   Reply With Quote
Old 11-13-2009, 03:01 AM   #2
Edmund Lee
War Room Member
 
edmltw's Avatar
 
Join Date: Jul 2009
Location: Singapore
Posts: 624
Blog Entries: 2
Thanks: 124
Thanked 91 Times in 57 Posts
Social Networking View Member's Myspace Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to edmltw
Default Re: Problem here need help!

Here is the code for that "upload.php"

<?php
/*

*/

class upload {
var $file, $filename, $destination, $permissions, $extensions, $tmp_filename, $message_location;

function upload($file = '', $destination = '', $permissions = '777', $extensions = '') {
$this->set_file($file);
$this->set_destination($destination);
$this->set_permissions($permissions);
$this->set_extensions($extensions);

$this->set_output_messages('direct');

if (tep_not_null($this->file) && tep_not_null($this->destination)) {
$this->set_output_messages('session');

if ( ($this->parse() == true) && ($this->save() == true) ) {
return true;
} else {
// self destruct
$this = null;

return false;
}
}
}

function parse() {
global $messageStack;

if (isset($_FILES[$this->file])) {
$file = array('name' => $_FILES[$this->file]['name'],
'type' => $_FILES[$this->file]['type'],
'size' => $_FILES[$this->file]['size'],
'tmp_name' => $_FILES[$this->file]['tmp_name']);
} elseif (isset($GLOBALS['HTTP_POST_FILES'][$this->file])) {
global $HTTP_POST_FILES;

$file = array('name' => $HTTP_POST_FILES[$this->file]['name'],
'type' => $HTTP_POST_FILES[$this->file]['type'],
'size' => $HTTP_POST_FILES[$this->file]['size'],
'tmp_name' => $HTTP_POST_FILES[$this->file]['tmp_name']);
} else {
$file = array('name' => (isset($GLOBALS[$this->file . '_name']) ? $GLOBALS[$this->file . '_name'] : ''),
'type' => (isset($GLOBALS[$this->file . '_type']) ? $GLOBALS[$this->file . '_type'] : ''),
'size' => (isset($GLOBALS[$this->file . '_size']) ? $GLOBALS[$this->file . '_size'] : ''),
'tmp_name' => (isset($GLOBALS[$this->file]) ? $GLOBALS[$this->file] : ''));
}

if ( tep_not_null($file['tmp_name']) && ($file['tmp_name'] != 'none') && is_uploaded_file($file['tmp_name']) ) {
if (sizeof($this->extensions) > 0) {
if (!in_array(strtolower(substr($file['name'], strrpos($file['name'], '.')+1)), $this->extensions)) {
if ($this->message_location == 'direct') {
$messageStack->add(ERROR_FILETYPE_NOT_ALLOWED, 'error');
} else {
$messageStack->add_session(ERROR_FILETYPE_NOT_ALLOWED, 'error');
}

return false;
}
}

$this->set_file($file);
$this->set_filename($file['name']);
$this->set_tmp_filename($file['tmp_name']);

return $this->check_destination();
} else {
if ($this->message_location == 'direct') {
$messageStack->add(WARNING_NO_FILE_UPLOADED, 'warning');
} else {
$messageStack->add_session(WARNING_NO_FILE_UPLOADED, 'warning');
}

return false;
}
}

function save() {
global $messageStack;

if (substr($this->destination, -1) != '/') $this->destination .= '/';

if (move_uploaded_file($this->file['tmp_name'], $this->destination . $this->filename)) {
chmod($this->destination . $this->filename, $this->permissions);

if ($this->message_location == 'direct') {
$messageStack->add(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
} else {
$messageStack->add_session(SUCCESS_FILE_SAVED_SUCCESSFULLY, 'success');
}

return true;
} else {
if ($this->message_location == 'direct') {
$messageStack->add(ERROR_FILE_NOT_SAVED, 'error');
} else {
$messageStack->add_session(ERROR_FILE_NOT_SAVED, 'error');
}

return false;
}
}

function set_file($file) {
$this->file = $file;
}

function set_destination($destination) {
$this->destination = $destination;
}

function set_permissions($permissions) {
$this->permissions = octdec($permissions);
}

function set_filename($filename) {
$this->filename = $filename;
}

function set_tmp_filename($filename) {
$this->tmp_filename = $filename;
}

function set_extensions($extensions) {
if (tep_not_null($extensions)) {
if (is_array($extensions)) {
$this->extensions = $extensions;
} else {
$this->extensions = array($extensions);
}
} else {
$this->extensions = array();
}
}

function check_destination() {
global $messageStack;

if (!is_writeable($this->destination)) {
if (is_dir($this->destination)) {
if ($this->message_location == 'direct') {
$messageStack->add(sprintf(ERROR_DESTINATION_NOT_WRITEABLE, $this->destination), 'error');
} else {
$messageStack->add_session(sprintf(ERROR_DESTINATION_NOT_WRITEAB LE, $this->destination), 'error');
}
} else {
if ($this->message_location == 'direct') {
$messageStack->add(sprintf(ERROR_DESTINATION_DOES_NOT_EXIST, $this->destination), 'error');
} else {
$messageStack->add_session(sprintf(ERROR_DESTINATION_DOES_NOT_EX IST, $this->destination), 'error');
}
}

return false;
} else {
return true;
}
}

function set_output_messages($location) {
switch ($location) {
case 'session':
$this->message_location = 'session';
break;
case 'direct':
default:
$this->message_location = 'direct';
break;
}
}
}
?>


Is anyone able to find the mistake within the script?

edmltw is offline   Reply With Quote
Old 11-13-2009, 03:28 AM   #3
HyperActive Warrior
War Room Member
 
Join Date: May 2009
Location: U.K
Posts: 197
Thanks: 5
Thanked 39 Times in 36 Posts
Social Networking View Member's Twitter Profile 
Default Re: Problem here need help!

Quote:
Originally Posted by edmltw View Post
// self destruct
Code:
} else {
// self destruct
           = null;

          return false;
        }
      }
    }
Thats the problem.

This should resolve the problem; although I cant vouch this will actually work how it was intended, nor cause any other problems.

unset($this);

Although, __destruct() would be better ......

Best Ways To Make Money Online

Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
“Yeah,” reply the bytes. “Make us a double.”
Luke Graham is offline   Reply With Quote
Old 11-13-2009, 04:52 AM   #4
Edmund Lee
War Room Member
 
edmltw's Avatar
 
Join Date: Jul 2009
Location: Singapore
Posts: 624
Blog Entries: 2
Thanks: 124
Thanked 91 Times in 57 Posts
Social Networking View Member's Myspace Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to edmltw
Default Re: Problem here need help!

Thanks Chaos for highlighting that out!

so instead of:

// self destruct
= null;

I will either put in

// unset($this)
= null;

or

// __destruct()
= null;

Am I right? Or did I place it wrongly?

Thanks again for the help Chaos!!

Quote:
Originally Posted by chaos69 View Post
Thats the problem.

This should resolve the problem; although I cant vouch this will actually work how it was intended, nor cause any other problems.

unset();

Although, __destruct() would be better ......

edmltw is offline   Reply With Quote
Old 11-13-2009, 05:04 AM   #5
Edmund Lee
War Room Member
 
edmltw's Avatar
 
Join Date: Jul 2009
Location: Singapore
Posts: 624
Blog Entries: 2
Thanks: 124
Thanked 91 Times in 57 Posts
Social Networking View Member's Myspace Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to edmltw
Default Re: Problem here need help!

Opps

I removed the ($this)

and then I got this:

Parse error: syntax error, unexpected '=' in /home/edmltw/public_html/admin/includes/classes/upload.php on line 24

Whoops

Did I do anything wrong?

Now it looks like this:

if ( ($this->parse() == true) && ($this->save() == true) ) {
return true;
} else {
// self destruct
= null;

return false;
}

What did I do wrong?

Thanks!!

edmltw is offline   Reply With Quote
Old 11-13-2009, 05:25 AM   #6
Active Warrior
War Room Member
 
Mike P Smith's Avatar
 
Join Date: Nov 2009
Location: Charlotte, NC, USA
Posts: 30
Thanks: 2
Thanked 4 Times in 3 Posts
Social Networking View Member's Twitter Profile 
Contact Info
Send a message via Skype™ to Mike P Smith
Default Re: Problem here need help!

You can't do unset($this) or anything like that (I think you could in PHP4, but that would have been a bug). The reason is that "unset" removes the variable from PHP, and with "$this" being the current instance of the class, "unset($this)" will attempt to remove the currently executing instance of the class, which is like starting your car then immediately removing the engine while it's running.

It's best if you turn the car off first. So if you're trying to reset variables within the class, you can do something like this:

} else {
// self destruct
$this->file=null;
$this->filename=null;
$this->destination=null;
$this->permissions=null;
$this->extensions=null;
$this->tmp_filename=null;
$this->message_location=null;
return false;
}
Mike P Smith is offline   Reply With Quote
Old 11-13-2009, 05:39 AM   #7
HyperActive Warrior
War Room Member
 
Join Date: May 2009
Location: U.K
Posts: 197
Thanks: 5
Thanked 39 Times in 36 Posts
Social Networking View Member's Twitter Profile 
Default Re: Problem here need help!

Quote:
Originally Posted by edmltw View Post
Opps

I removed the ()
The formatting broke it i think

$this=null; is the bad line. unset($this); will fix it, but as i said may still have undesirable results.

You will need to look into a proper desconstructor in the object, which is referenced as __destruct()

Best Ways To Make Money Online

Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
“Yeah,” reply the bytes. “Make us a double.”
Luke Graham is offline   Reply With Quote
Old 11-13-2009, 06:08 AM   #8
Edmund Lee
War Room Member
 
edmltw's Avatar
 
Join Date: Jul 2009
Location: Singapore
Posts: 624
Blog Entries: 2
Thanks: 124
Thanked 91 Times in 57 Posts
Social Networking View Member's Myspace Profile  View Member's YouTube Profile
Contact Info
Send a message via Skype™ to edmltw
Default Re: Problem here need help!

Thanks guys!! The php scripts are working fine now..

Now all I have to do is to settle the MySqL issues.. Rrrr...

Shouldn't have gotten a cheap script.. All the bugs are irritating. haha..

Thanks again guys!

Ed

edmltw is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
problem

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 02:09 AM.