How to upload file to custom folder?

I am trying to upload a file (MP4 or MOV) to a custom folder, I need to access the original file not one served by php.  I edited the File upload but can't seem to get it to save in my custom folder.  Is their something Im missing or a elgg feature that disables this from happening? I'm on elgg 1.12.


$target_dir =  $_SERVER['DOCUMENT_ROOT'].'/mysite/uploads/videos/';

$target_file = $target_dir . basename($_FILES["upload"]["name"]);

move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)

  • Just don't do it.

    If you insist, use data directory, and not public paths. 

    $target_dir = elgg_get_config('dataroot') . 'uploads/videos/';
    if (!is_dir($target_dir)) {
       // create dir

    And you have to consider colliding filenames. Also, you won't be to map files to users, or take any of the advantages that come with using ElggFile.

  • I was going to name the filenames as the entity guids, so I can easily link them to the entity. Then only allow mov or mp4 for uploads. What are the issues I can run into doing this using your method data directory?

  • There are plenty of issues you will run into, especially if you are not familiar enough with Elgg. 

    Why don't you use latest Elgg version?

  • Current hosting supports up to 5.4 php and. Edited quite a few plugins... lack of time to move it and troubleshoot.