MachForm

MachForm

Securing MachForm

Keeping Uploaded Files Private

How to move the upload folder outside your website's folder, on a new or existing MachForm Self-Hosted installation.

Last updated on 27 Nov, 2026

This article applies to MachForm Self-Hosted only.

What's public and what's private

MachForm keeps files in two folders.

  • The data folder (machform/data) holds what your forms show to everyone: images and PDFs you add in the form builder, and your themes' styles and images. Your web server must keep serving it. Don't move it.

  • The upload folder holds the files people upload with their entries, plus PDFs MachForm is about to attach to a notification email. These are private. MachForm makes it inside the data folder when it's installed, as machform/data/files followed by 32 random letters and digits. Its exact path is in Settings → Miscellaneous → More options → File Upload Folder.

MachForm itself never serves the upload folder as a folder. A file is opened through MachForm's links (download.php and view_img.php), which are in the entry's page and in notification emails. Each link holds a long random value that can't be guessed, so anyone who has the link can open that one file, the same way they can read the email it came in. Files uploaded before version 31 have a weaker value in their links, made from the time of the upload and PHP's ordinary random numbers instead of a secure random source.

A folder inside your website's folder can also be reached by its address, unless your web server refuses it. Moving the upload folder outside the website's folder means only MachForm can reach it.

If your MachForm was installed before version 27, some older uploads may still be in machform/data/form_N/files (N is a form's number). Those are private files in a public folder. Settings tells you when there are any, and moves them for you (step 4 below).

Settings shows where you stand. In Settings → Miscellaneous → More options → File Upload Folder, a line under the box says when the upload folder is inside your website's folder. When it is, your browser asks your web server for a file MachForm placed there, as a visitor would, and the line then says either that anyone with a file's address can open it, or that your server refuses requests to it.

A new installation

Do this right after installing, before your forms collect entries.

  1. Create a folder outside your website's folder. For example, if your website is in /var/www/html, use /var/private/machform-uploads:

Shellsudo mkdir -p /var/private/machform-uploads
sudo chown www-data:www-data /var/private/machform-uploads
sudo chmod 750 /var/private/machform-uploads

Use the account PHP runs as (www-data on Debian and Ubuntu, apache or nginx on Red Hat and its family, or the PHP-FPM pool's user). On Windows, use a folder such as D:\MachFormUploads and give the application pool's identity (or IIS_IUSRS) Modify permission on it.

  1. Copy what MachForm already made there. Replace filesXXXX with your folder's name from Settings:

Shellsudo rsync -a /var/www/html/machform/data/filesXXXX/ /var/private/machform-uploads/
sudo chown -R www-data:www-data /var/private/machform-uploads
  1. Go to Settings → Miscellaneous → More options → File Upload Folder, enter the folder's full path, and save. The line under the box says "Writable." when MachForm can use it.

  2. Submit a test entry with a file, open its file from the entry's page, then delete the test entry and the old folder (machform/data/filesXXXX, never machform/data itself).

For permissions on SELinux and hosts with open_basedir, see step 5 below.

An existing installation

You need access to the server's files. Nothing is deleted until the end, so you can go back at any time before step 8.

  1. Back up your MachForm folder and database.

  2. Create the new folder as in step 1 of a new installation.

  3. Copy the upload folder's contents into it, keeping the folder structure. Replace filesXXXX with your folder's name from Settings:

Shellsudo rsync -a /var/www/html/machform/data/filesXXXX/ /var/private/machform-uploads/

Copy the contents only (note the slash after filesXXXX/), not the folder itself.

  1. Move older uploads, if there are any. Do this after step 6. When Settings says files uploaded before version 27 are in the data folder, click Move them. MachForm copies each file into the upload folder, checks that the copy is identical, and only then deletes the original. A file that can't be moved stays where it is, and Settings lists it. Download links keep working.

If you prefer to copy them yourself, copy each form's files folder from the data folder:

Shellcd /var/www/html/machform/data
for dir in form_*/files; do sudo mkdir -p "/var/private/machform-uploads/$dir"; sudo rsync -a "$dir/" "/var/private/machform-uploads/$dir/"; done
  1. Set the permissions so PHP can read and write the copies:

Shellsudo chown -R www-data:www-data /var/private/machform-uploads

On a server with SELinux, also allow the web server to write there:

Shellsudo chcon -R -t httpd_sys_rw_content_t /var/private/machform-uploads

If your host limits PHP to some folders (open_basedir), add the new folder to that list.

  1. Change the setting. In Settings → Miscellaneous → More options → File Upload Folder, enter the new folder's full path and save. The line under the box should say "Writable."

  2. Check that everything still works:

    • open an entry that has an uploaded file, and open its image and its download link;

    • open a file link from a notification email sent before the change: links already sent keep working;

    • submit a test entry with a file, open it, then delete the test entry.

  3. Delete the old files. Once everything works, delete only the old upload folder:

Shellsudo rm -rf /var/www/html/machform/data/filesXXXX

If you copied older uploads yourself, delete only the files inside each data/form_N/files folder (Move them already did this). Never delete machform/data itself: your forms' images and themes are there.

  1. Check the old address is refused. In a browser, open https://your-site/machform/data/filesXXXX/index.html. It should say the page wasn't found. In Settings, the line about the website's folder is gone once the upload folder is outside it.

To go back before step 8, enter the old folder's path in Settings again and copy back any file uploaded since:

Shellsudo rsync -a /var/private/machform-uploads/ /var/www/html/machform/data/filesXXXX/

If you keep the upload folder where it is

If you can't create a folder outside your website, add a rule to your web server that refuses requests for the upload folder, for older uploads and for the data folder's temp folder. The data folder's other files stay public. The rules also stop scripts from running in the data folder, which MachForm never does. Change /machform/ and the folder paths to yours.

Apache 2.4, in your site's configuration:

HTML<Directory "/var/www/html/machform/data">
	<FilesMatch "(?i)\.(php[0-9]?|pht|phtml|phps|phar|pl|py|cgi|sh)(\.|$)">
		Require all denied
	</FilesMatch>
</Directory>
<DirectoryMatch "^/var/www/html/machform/data/(files[^/]*|temp|form_[0-9]+/files)/">
	Require all denied
</DirectoryMatch>

Installs made with version 27 or later, and installs upgraded to version 27, have an .htaccess file in the upload folder that refuses every request, so an Apache that reads .htaccess files already refuses the upload folder. Uploads from before version 27 in data/form_N/files aren't covered by it: move them as in step 4.

nginx, inside your site's server block:

JavaScriptlocation ^~ /machform/data/ {
	location ~ ^/machform/data/(files[^/]*|temp|form_[0-9]+/files)/ { return 404; }
	location ~* \.(php[0-9]?|pht|phtml|phps|phar|pl|py|cgi|sh)(\.|$) { return 403; }
}

IIS, a web.config file in the data folder. Replace filesXXXX with your upload folder's name:

XML<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<system.webServer>
		<security>
			<requestFiltering>
				<hiddenSegments applyToWebDAV="true">
					<add segment="filesXXXX" />
					<add segment="files" />
					<add segment="temp" />
				</hiddenSegments>
				<fileExtensions allowUnlisted="true">
					<add fileExtension=".php" allowed="false" />
					<add fileExtension=".php5" allowed="false" />
					<add fileExtension=".php7" allowed="false" />
					<add fileExtension=".php8" allowed="false" />
					<add fileExtension=".phtml" allowed="false" />
					<add fileExtension=".phar" allowed="false" />
					<add fileExtension=".pl" allowed="false" />
					<add fileExtension=".py" allowed="false" />
					<add fileExtension=".cgi" allowed="false" />
					<add fileExtension=".sh" allowed="false" />
				</fileExtensions>
			</requestFiltering>
		</security>
	</system.webServer>
</configuration>

This hides every folder named files or temp inside the data folder, which is where uploads are kept; your forms' images and themes aren't affected.

Then check: Settings should say "Inside the website's folder, but your server refuses requests to it.", and your forms' images and every entry's files should still open.

Several servers behind a load balancer

  • Put both the upload folder and the data folder on storage every server shares (NFS, an SMB share, or your hosting provider's shared file storage), mounted at the same path on each server. One server can receive a file and another the form it belongs to, and the builder's images and themes are written on whichever server you're using.

  • Sessions are kept in the database, so you don't need sticky sessions.

  • Keep MachForm's files and config.php the same on every server, and update them all together.

  • Set the visitor's real address from the load balancer's header (Apache's mod_remoteip, nginx's real_ip module, or your load balancer's own setting). MachForm uses it for the sign-in's IP address list, account locking and upload limits.

Don't link the private folder back

Don't make the private folder reachable from your website again with a symbolic link, an alias or a virtual directory: that makes it public. MachForm never creates such links.

Did you find this article helpful?