We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 445
    • 13 Posts
    Hello, I am trying to use the move_uploaded_file() function in a module I’m writing, but when I try and let the user upload a file via a form, here is the error message I get:

    Warning: move_uploaded_file(modx/assets/media/storelist.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/mtzionwi/public_html/modx/manager/processors/execute_module.processor.php(114) : eval()’d code on line 44

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ’/var/tmp/phptl055q’ to ’modx/assets/media/storelist.txt’ in /home/mtzionwi/public_html/modx/manager/processors/execute_module.processor.php(114) : eval()’d code on line 44
    fail

    I am using this code to upload the file:

    $target = "modx/assets/media/".basename($filename);
    echo "The filename is: $target";
    if(move_uploaded_file($_FILES['mediafile']['tmp_name'], $target))
    echo "success moving file";
    else
    echo "fail moving file";
    


    The full path to the folder I want to upload to is: "modx/assets/media"

    My directory structure is:
    public_html/
    modx/
    assets/
    media/
      • 445
      • 13 Posts
      The workaround I am using for this is to use the full path by saying $_SERVER[’DOCUMENT_ROOT’] before the path name.
        • 22303 MODX Staff
        • 10,725 Posts
        You could also use the MODx base_path configuration variable...
        $target = $modx->config['base_path'] . "modx/assets/media/".basename($filename);