Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Path Variable

XarcellXarcell North Carolina
edited July 2012 in Vanilla 2.0 - 2.8

I'm new to vanilla and not very good with php. I'm trying to create a plugin. My question for now is how do I proper the proper absolute path? Is a variable used, or something else?

For example how do I get the:

Is something similar to this used?


  • Options

    dirname(__FILE__) is the absolute path of the directory you are currently in, or the directory that the current script is executing from to be precise.

    so you can do


    you also have various cosntants in Garden


    DS is the director separator.

    grep is your friend.

  • Options
    XarcellXarcell North Carolina

    I'm trying to wrap my head around what your saying. I understand half of it. However, I don't need to point to a file(include), I need to point to a directory where files are to be deposited.

    // files storage folder
    $dir = '/home/web/sitecom/plugin/images/';

    So would it be something like this?
    define('PATH_ROOT' . 'plugin/images/') = $dir;

    FYI, I cannot get this stupid editor to display code properly.

  • Options

    I would take a more general course in php, so you get a better overall understanding. Also any C based language will help.

    if the script is already in the directory you can use

    define('MY_IMG_DIR' , dirname(__FILE__).DS.'images');


    define('MY_IMG_DIR' , PATH_PLUGINS.DS.'MyPlugin'.DS.'images');

    grep is your friend.

  • Options
    peregrineperegrine MVP
    edited July 2012

    define is just setting a CONSTANT rather than a variable (which can change)

    so when you use it it,

    after you define it.

    you don't use the $ as you would in $my_img_dir

    you would use MY_IMG_DIR

    as in echo MY_IMG_DIR;

    vs a variable

    echo $my_img_dir;

    and you would want a relative path not an absolute path if you plan on uploading the plugin so other can use.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    XarcellXarcell North Carolina

    I'm just trying to get this script to work as part of the editor plugin.

    // This is a simplified example, which doesn't cover security of uploaded images. 
    // This example just demonstrate the logic behind the process. 
    // files storage folder
    $dir = '/home/web/sitecom/redactor/images/';
    $_FILES['file']['type'] = strtolower($_FILES['file']['type']);
    if ($_FILES['file']['type'] == 'image/png' 
    || $_FILES['file']['type'] == 'image/jpg' 
    || $_FILES['file']['type'] == 'image/gif' 
    || $_FILES['file']['type'] == 'image/jpeg'
    || $_FILES['file']['type'] == 'image/pjpeg')
        // setting file's mysterious name
        $file = $dir.md5(date('YmdHis')).'.jpg';
        // copying
        copy($_FILES['file']['tmp_name'], $file);
        // displaying file
        echo '<img src="/tmp/images/'.$file.'" />';
Sign In or Register to comment.