The File System on VIP Go

VIP Go platform specific

This document is for sites running on VIP Go.

Learn more

Overview #

The VIP Platform has been designed with for high-scale performance and security. One of the ways we do that is to run all web servers in read-only mode. This helps protect applications on the platform against many common form of attack (e.g. vulnerabilities that allow installation of backdoor shells and other malicious files); allows for automated, high-capacity horizontal scaling; and dynamic image resizing and manipulation.

↑ Top ↑

Media Uploads #

The VIP Platform stores all uploaded media in a globally distributed object store called the VIP Files Service. This is seamlessly integrated with your WordPress application and all common operation including uploads, cropping, editing, and deletes work as expected.

All images uploaded to the VIP Files Service can make use of the Photon API, which allows for dynamic resizing and other manipulation (cropping, letterboxing, filters, etc.). Because image sizes all are created on-the-fly, uploads are significantly faster and changes to image sizes is much easier (no need to run scripts to regenerate files).

Files uploaded to the Files Service are treated as case-insensitive.

Programmatic Access to Media Uploads #

For programmatic access to media stored in the VIP Files Service, such as uploading and modifying files, you can use several different APIs.

For simple file uploads, the media_handle_sideload, media_sideload_image, or wp_upload_bits functions are very easy to work with.

For more complex interactions, we’ve integrated a custom PHP Stream Wrapper, which allows most filesystem functions (e.g. fopen, fwrite, file_put_contents, etc.) to work with media uploads. This means that most plugins that interact with media uploads will work on the VIP Platform without any modifications. There are some caveats

A few caveats to be aware of:

  • This only works for the uploads directory (i.e. paths that begin with /wp-content/uploads/; other paths will not work).
  • We default to a year/month directory structure for media uploads. This can be overridden by adding the following filter to your theme’s functions.php file:
    add_filter( 'pre_option_uploads_use_yearmonth_folders', function() {return '0';}, 9999 );
  • You must use the WordPress function wp_get_upload_dir() or wp_upload_dir() to generate the correct, writeable path (hard-coding a path like /wp-content/uploads/... will not work).
  • Currently, not all filesystem functions and operations are supported (e.g. directory traversal).
  • Not all use cases are ideal or supported (e.g. files with high volumes of updates, such as logging).
  • Because communication with the VIP Files Service happens over HTTP, high number of function calls (e.g. lots of file_exists checks) can result in a performance hit and should be used with caution.
  • file_exists will always return true for extension-free values (e.g. directory names).

↑ Top ↑

Examples #

Here’s a simple example of how to upload a file using PHP functions:

$csv_content = '1,hello,admin';

$upload_dir = wp_get_upload_dir()['basedir'];

$file_path = $upload_dir . '/csv/updated.csv';

file_put_contents( $file_path, $csv_content );

// The file will now be accessible at <a href=""></a>

Here’s an example that parses an uploaded CSV and stores the contents in a variable:

$csv_attachment = get_attached_file( 1234 );

$csv_file = file( $csv_attachment );

$csv_content = array_map( 'str_getcsv', $csv_file );

↑ Top ↑

Local File Operations #

There may be cases where you need to perform local manipulations to temporary files (e.g. download a zip, extract its contents, and then upload them to WordPress). For these cases, you can use the system temp directory, which is the only local, writeable path on web servers on the VIP Platform.

A few things to keep in mind:

  • Use get_temp_dir() to find the right path. Or if you need to generate a temporary file, use wp_tempnam().
  • You should clean up and remove all files after they’re no longer needed. Use unlink() to remove those files.
  • Files and directories can only be relied on for the duration of the current request.
    • Each request may be served by a different container and the sequence of requests from a given user are not guaranteed to be served by the same container.
    • Containers are transient and may be created and destroyed due to autoscaling.

If you have any questions about the VIP Files Service or working with the filesystem on the VIP Platform, please don’t hesitate to get in touch with the VIP team so we can work with you on the implementation.

Ready to get started?

Drop us a note.

No matter where you are in the planning process, we’re happy to help, and we’re actual humans here on the other side of the form. 👋 We’re here to discuss your challenges and plans, evaluate your existing resources or a potential partner, or even make some initial recommendations. And, of course, we’re here to help any time you’re in the market for some robust WordPress awesomeness.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.