Files
What happens to a file between upload and playback
Upload Setting
To change upload setting, go to "RKHM admin-area -> Setting -> Files -> Upload setting"
If you wish to change where files are uploaded to, go to "RKHM admin-area -> Setting -> Files -> Storage setting" instead
Many of upload settings can be set separately for different files. For example, you can allow users to upload only <1mb images unless they are uploading a music-track-cover
Background Processing
Some file operations require time & server resource. HLS encrypting an mp3 file takes just a few second, but converting 4k video to lower qualities takes longer. This execution time can cause problems for users that are trying to upload big files to your app as the operation will time-out when they try to submit their content. To bypass this, you can enable background processing for files. File operations will not be done as user submit the files, instead they will be done by cronjob in the background. If your app is working with big files, especially videos, and you want to offer format/quality change support, enable background processing
You can see the background execution log in "RKHM admin-area -> Setting -> Cronjob -> Run logs"
Chunk upload
When user selects a file for upload, instead of sending that file in 1 big piece to server, script will use third party libraries to cut the file into smaller chunks and upload them as 1 by then. At the end, these chunks are merged back into the file on server. This option can be used to bypass any upload/execution limits on both server & client end
Image rules
All options are explained in the setting page. You can choose min/max size. min/max dimensions, acceptable formats & resize. If you enable resize ( enabled by default ), all uploaded images are resized to different dimensions to be used on smaller places/devices. Resizing images means saving multiple versions of an image but considering how much bandwidth your server & your users are going to save it's definitely worth it. Also, if you can install new binaries on your server, you can make RKHM create WebP version of your images to save traffic!
Video rules
You can set min/max size, min/max width. Acceptable formats. Script can use FFmpeg to create lower qualities of video & HLS-encrypt them
Audio rules
You can choose min/max size. Min bitrate & acceptable formats
Waveforms: Script will use FFmpeg ( if available ) or Wavesurfer.js to create waveforms for uploaded audio tracks. Current theme "Shady" does not support waveforms and they are not displayed anywhere! But future/custom themes might support it
Protect premium files: Priced files are not uploaded to third-party hosts and they can't be publicly accessed More info
Preview for premium files: Script can use FFmpeg to create preview ( shorter, lower in quality ) for uploaded priced items. These previews will be free-to-use for everyone
Lower quality: Script can use FFmpeg to lower quality of uploaded audios to 256k, 192k, 128k, 64k
HLS encryption: Encrypt your files so they can't be played outside your app. More info
File Storage
in case you need to store your files in a place other than your server, you can use the RKHM storage feature. You can define as many storages as you need as long as they support FTP or are AWS-compatible
You can configure script to upload different types of media to different storages. For example you can setup script to upload all track-images to server1, all track-mp3s to server2, all podcasts to server3 and etc
File Protection
RKHM offers several features to help you protect your assets
The most basic version of file protection, is not making them public. All protected files can be placed to "path_to_rkhm/files/protected" which can't be accessed by public. All requests to this directory are redirected to "path_to_rkhm/protector.php" which checks user-ip, user-agent & keys to see if access has been given to the visitor. This way, your files can't be publicly shared by URL but people will have access to original file and many download managers can clone browser-sessions to download these types of files. Also you can't use third-party storages with this option since they are public
The right way - HLS
Files are made from 1s and 0s. Usually these 1s and 0s are in a order that can be understood by certain applications. Same goes for all multi media files such as mp3, mp4, flac and etc. Players can't play everything, the input file has to be understandable to them
Using FFmpeg & HLS encryption, script can cut your multimedia file into smaller chunks, then generate and use a key to encrypt those chunks. Players can play the file only if they know the address of every chunk and also the path to key. In other words, even if users find the public path to your files, it has been cut into pieces, and those pieces can't be played by their local player. An expert can still download all chunks manually, then download the key manually, then proceed to merge everything together but it's hard and time consuming so HLS is currently the best & cheapest way to protect your files
And that's not all. Streaming HLS files is much faster & cheaper for users as well and it will increase your app's overall performance a lot. Also you can use third party storages to store them. All the major streaming services such as Spotify are using HLS or similar technologies
The only down side to HLS encryption is that if you plan to offer download, you have to keep 2 versions of files, one HLS encrypted that can only be played by your app's browser, and the original file that can be played by any player. This means twice the storage fee. A work around can be another feature of RKHM, offering in-app downloading. Instead of letting users download the content to their device, you can allow them to download them to your app. Later, even when offline, they can use your app to play these downloaded files
File removal
When you remove an object or item that has files attached, script will check if those attached files are not used by any other item, if not, script will proceed to remove them from wherever they were stored. You don't have to worry about removing old files
Currently script doesn't remove folders after removing files
File cleaning
The "path_ro_rkhm/files/unused" is the directory RKHM uses for temporary files. When an admin or user uploads something, after file validation, their uploaded item is moved to temporary-files-directory. It will stay there until the process it belongs to is fully executed or 12 hours has passed
For example, if you edit an object in "RKHM admin-area" and upload a new cover, that cover is moved to temporary-files-directory. When you hit "Edit" button, that file is processed ( resized, reformatted, etc ) and placed into final storage that might be your own server or third party servers