• Hi,

    I am using the file uploader for a web server. So when a new file is uploaded via the plugin, I want to recognize this and automatically do some stuff like generating a folder somewhere outside the plugin folder where future results are stored.

    So my idea was now to easily adjust the

    wfu_io.php

    script to also generate the folder for me. So what I did was adding some code to the

    wfu_create_directory

    function like this:

    mkdir($path, 0777, true);
    // my new code
    mkdir(“/root/results/foo”, 0777, true);

    Anyway, the new ‘foo’ folder is not generated and I don’t know why? When I modify something like this:

    mkdir($path . “/foo”, 0777, true);

    then the ‘foo’ folder is generated within

    ‘wp-content/uploads/foo’

    Is there maybe a problem by generating folders outside the plugin folder? Can I anyway do this somehow?

    Thank you very much!
    Martin

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author nickboss

    (@nickboss)

    Hi Martin,

    changing the plugin code will result that you will loose your customizations if you update it. I would recommend to use the plugin’s filters for this (e.g. wfu_after_upload filter). Here is a description of the plugin’s filters.

    The path you entered is not correct. The web server does not recognize a ‘root’ path. Perhaps it should be something like this:

    mkdir(ABSPATH.”/results/foo”, 0777, true);

    Regards

    Nickolas

    Thread Starter djikstra

    (@djikstra)

    Hi Nickolas,

    thanks for the hint. Unfortunately I am not so experienced in PHP stuff, so how to access this wfu_after_upload function?

    I found the template in the _wfu_hook_templates.php file. But how is it executed if I put my code for creating the directory there? Or do I have to create a new php file inside the lip folder and include the function?

    Thanks for your help!
    Martin

    Plugin Author nickboss

    (@nickboss)

    If you have the Professional version you can create a hook using the plugin’s Hooks feature. If you have the Free version you need to add the code inside functions.php file of your website.

    Regards

    Nickolas

    Thread Starter djikstra

    (@djikstra)

    Hi,

    I have the professional version. I just created a new hook and added code from the ‘After file was completely uploaded’ template. When I save this I already get the message:

    “Hook has been saved but cannot be activated because the code contains errors. Please check its syntax.”

    But shouldnt be the syntax of the imported template ok? Or did I miss something regarding the implementation of new hooks?

    Thanks!

    Plugin Author nickboss

    (@nickboss)

    Hi, in some web servers it throws this error even if the code is correct because of some security settings. Please go to Settings and activate option ModSecurity Restrictions.

    Regards

    Nickolas

    Thread Starter djikstra

    (@djikstra)

    Hi Nick,

    thx, works. What I want to do now:

    I want to access the path of the uploaded file within this function. If I understand the comment correctly, I should find this in the

    $additional_data

    array. But how to access this value?

    $file_path=$additional_data["file_path"];

    ???

    My upload file path looks like this:

    wp-content/uploads/poseidon/data/poseidon-stamp_1492194083367/poseidon-id_test/p19.fna

    and at the end I want to have ‘1492194083367’ stored in a variable.

    Thanks!

    Plugin Author nickboss

    (@nickboss)

    what filter have you used?

    Nickolas

    Thread Starter djikstra

    (@djikstra)

    Ah, sorry, I am using the

    wfu_after_file_loaded_handler

    filter.

    Plugin Author nickboss

    (@nickboss)

    yes you have set $file_path correctly.

    You can extract the number you mentioned (1492194083367) from the path like this:

    $code = preg_replace("/^.*poseidon-stamp_([0-9]*)\/.*$/", "$1", $file_path);

    Regards

    Nickolas

    • This reply was modified 7 years, 11 months ago by nickboss.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Mkdir outside the plugin folder when upload is finished’ is closed to new replies.