DirectAdmin Knowledge Base and Support

DirectAdmin is a web panel for a simple administration of both virtual and dedicated servers. DirectAdmin is faster, safe and more powerful than any other CP. And we know how to customize and support it.

File uploading within a Directadmin plugin

| 12:59:26 25.06.2014

File uploading in a Directadmin plugin is possible, and there is nothing difficult if to say in general. Let me show some basic moments with the help of which you can achieve the desired.

HTML upload form

Directadmin does not add any special requirements for it. So you are free to use any which you may find. Here is below a simple example of such a form:

<form method="POST" enctype="multipart/form-data" action="?">
File to upload: <input type="file" name="upfile"><br>
Notes about the file: <input type="text" name="note"><br>
<input type="submit" value="Press"> to upload the file!

TEMP directory

By default Directadmin uses it's own directory for temp files. The directory is located in /home/tmp/. Of course you may symlink /tmp to /home/tmp for more security.

PHP coding

There are some critical differences which should be considered when writing a plugin for Directadmin. There are no such variables as $_POST, $_GET, $_FILES, etc. We may use the only existing $_SERVER, which usually contains all of them as strings. So we need to do some parsing:

    if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'])
        parse_str($_SERVER['QUERY_STRING'], $_GET);
    if (isset($_SERVER['POST']) && $_SERVER['POST'])
        parse_str($_SERVER['POST'], $_POST);

Information on an uploaded file will be stored in $_POST var here. And it will be only a full path to a temporary stored file in /home/tmp/. In our example it will be: $_POST['upfile']


So, the simple PHP code:


would result in priting of simple output:


Since now you know how to upload files in a Directadmin plugin. Copy a file to a location of your needs, and have fun.


That should be considered that as for now Directadmin will chown an uploaded file to nobody:nobody and set restrictive permissions to 600. And to copy such a file your plugin should run as root via a suid wrapper.

About Us
We are a team of professionals, and specialize in installation, configuring and managing of remote virtual and dedicated servers powered by Linux/Unix-like OS with DirectAdmin. We support various sets of software, including web-servers Apache, Nginx; internet domain name servers Bind, PowerDNS; mail-servers with POP3, IMAP and SMTP, FTP-servers, etc. After years of working through the most complex server challenges our team has gathered valuable experience and universal solutions suitable for everyday tasks. We are here to lend you a helping hand and take care of your servers in order to let you have enough time to do more of what you love.

All of the information and data on this site is for informational purposes only and is provided for the convenience of the user.
Powered by: Amiro.CMS - Free edition