Jump to content

Standardize file properties to PHP equivalents


adrian
 Share

Recommended Posts

Hey Ryan,

I am sure you have good reason for the approach you have taken - you usually do, and usually teach me something I don't know, but I was thinking it would be nice if we had the exact same options as PHP ie:

dirname
basename
extension
filename
 
I know there is some overlap, but there seems to be some difference in behavior as well. In particular what I am missing is an emulation of PHP's filename which returns the basename without the extension. This of course would be a problematic backwards compatibility change.
 
Anyway, just wanted to throw it out there :)
 
 
Link to comment
Share on other sites

The only two of those that are PHP functions are dirname() and basename(). As far as I know, filename() and extension() are not PHP functions? So I'm not sure what you mean when you say "emulation of PHP's filename which returns the basename without the extension"? But I think I can tell you how to get the result you asked for of "basename without extension":

echo basename($file->filename, '.jpg'); // substitute .jpg with extension you want to remove.
Link to comment
Share on other sites

Sorry Ryan, I wasn't very clear on this - I was referring to the pathinfo options in php for: 

dirname
basename
extension
filename
 
image.png.4d868f8aab90c4c98a9f85cf61aa1776.png
 
Because I don't know what the extension is, I actually used which works  great.
pathinfo($file->filename,PATHINFO_FILENAME)

I am fine with using this, rather than needing PW option. I think what prompted this email was the description in the API cheatsheet for $file->name which says: "Returns the filename without the path (basename)". I thought it would be nice if $file->name became $file->basename to make this clearer for those people used to PHP. Then it just seemed logical to have the other pathinfo options also availble.

Anyway, really no big deal at all - just thinking out loud really :)

Link to comment
Share on other sites

Actually $file->basename is there too. It's the same thing as $file->name. The $file->name is mainly there for consistency with other PW objects, in that we want everything in ProcessWire to reliably have a 'name' property. But I usually use $file->basename myself.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...