Plugin not working with EE2
Reported by gilesbutler | March 31st, 2010 @ 02:27 PM
Hi,
Im trying to use the plugin to display a files size from a custom field but as soon as i include the plugins tags {exp:human_filesize}{/exp:human_filesize}
I get the following 2 errors.
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: human_filesize/pi.human_filesize.php
Line Number: 66
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/filthyha/public_html/theccwire/wiresystem/core/Exceptions.php:166)
Filename: core/Common.php
Line Number: 417
If you have any ideas Id really appreciate it :)
Thanks
Giles
Comments and changes to this ticket
-
George Ornbo March 8th, 2011 @ 09:03 PM
- Milestone order changed from 0 to 0
(I'm not George; I simply clicked the Tickets link here: http://shapeshed.github.com/expressionengine/plugins/filesize/ which automatically logged me in as him.)
I found the same bug with this plugin:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: human_filesize/pi.human_filesize.php
Line Number: 66
I took a look on line 66 of the plugin and I found this:
$this->file = trim(strip_tags($TMPL->tagdata));
and figured the error must have something to do with $TMPL, so I stuck an
if
statement around that line like this:if ($TMPL) { $this->file = trim(strip_tags($TMPL->tagdata)); }
and now I don't get that error anymore.
Hope this helps someone!
-
ffub May 25th, 2011 @ 03:32 PM
The above fix will hide the error, but the plugin will not be able to access the actual filename. The below works in EE2, untested in EE1.
Replace:
$this->file = trim(strip_tags($TMPL->tagdata));
with:
$this->EE =& get_instance(); $this->file = trim(strip_tags($this->EE->TMPL->tagdata));
A conditional may be necessary to add support for EE1:
if ($TMPL) { $this->file = trim(strip_tags($TMPL->tagdata)); } else { $this->EE =& get_instance(); $this->file = trim(strip_tags($this->EE->TMPL->tagdata)); }
The above is untested in EE1 though as I do not have an installation handy.
Thanks,
Stephen -
masni bennett May 18th, 2012 @ 07:05 AM
This is how I hacked it recently to get it working with full file paths.
function Human_filesize() { global $TMPL, $FNS; $this->EE =& get_instance(); // Grab the site url $path = $this->EE->functions->fetch_site_index(); $path = str_replace("index.php", "", $path); $this->file = trim(strip_tags($this->EE->TMPL->tagdata)); $this->file = str_replace($path, "", $this->file); // Remove the site url $this->file = str_replace(SLASH, '/', $this->file); if (!file_exists($this->file)) { return $this->error_message; } // Continue with original code...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
An ExpressionEngine plugin to shows the size of a file in human readable format