Search code examples
phpfile-uploaduploadtransfermodx

PHP, MoDX: Upload file from custom PHP Snippet


I have a snippet that I want to use to upload a file.

The script seems to be running fine until it gets to the point where PHP transfers the file from temp docs to my own folder.

My folder is called 'uploads' and is the root.

On ModX the PHP files directory is

/core/cache/includes/elements/modsnippet

I cannot seem to figure out a way to direct the script to send the file back from the modsnippet directory to the public_html/uploads directory.

So far I have tried:

move_uploaded_file($_FILES['instlogo']['tmp_name'], dirname(__FILE__) . "/../../../../uploads".$new_file_name)

;

as well as absolute paths, eg:

http://mysite.com/uploads

To no avail.

Would anyone know a way of doing this correctly? Thanks!

(ps: permissions on that folder are 777)


Solution

  • can you try something like:

    $my_uploads = $modx->getOption('base_path').'uploads/';
    
    move_uploaded_file($_FILES['instlogo']['tmp_name'], $my_uploads.$new_file_name)
    

    the base_path option will give you the full file system path [from the server root]

    if not & you are getting a filesystem error, the server logs [aapche] should be telling you why. Do you have access to them?