<?PHPfunctionSae_write ($file,$content) {file_put_contents(Sae_tmp_path. " /".$file,$content); } functionSae_read ($file) {return file_get_contents(Sae_tmp_path. " /".$file); } ?>
<?php sae_write ("1.txt", "Test"); $rs=sae_read ("1.txt"); Print_r($rs); ?>
When processing the upload picture, the original image is post, can be directly move_uploaded_file to Storage.
When it is necessary to add a watermark to the uploaded image, it is usually processed first and then saved to the TMPFS that supports temporary read-write, then writes the file to storage, but cannot use Move_uploaded_file again (bool Move_uploaded_ File (string $filename, string $destination)) function, because if the $filename is considered illegal when $filename http POST upload that is not over HTTP, the function will not perform any action to return FL Ase.
This can be done simply with the following statement:
File_put_contents ($filaname, file_get_contents ($tmpfile));
================
TmpFS
Because of platform security, the SAE limits the user's use of the local IO, but this may have caused a lot of inconvenience for some traditional PHP projects, Because they all have more or less operations on the local IO, like Smarty's compiled template. To solve this problem, SAE provides TMPFS functionality. TMPFS allows developers to temporarily read and write local IO via standard IO functions, which facilitates porting of many non-SAE projects.
Special Note: The lifetime of the
temporary file is equivalent to the PHP request, which means that all temporary files written to Tmpfs are destroyed when the PHP request is completed
Tmpfs is a local temporary file, not a shared storage, and the SAE is a fully distributed environment. So different requests between the TMPFS sharing operation file
Tmpfs operation files are limited to Sae_tmp_path directory, and different apps Sae_tmp_path is different
Tmpfs files for pure memory storage
Scenario
Users can persist storage, use storage or MySQL storage, and cache storage using the Memcache service store, TMPFS is the read and write requirement of a temporary file that satisfies a user's request. For example, grab a URL image, determine the size, and then decide whether to write storage. There are several scenarios in which you need to generate files locally:
Cache
Configuration files
static files
Temporary files
Usage guides
Examples:
appname:saetest
AppVersion : 1
in a php file:
file_put_contents (Sae_tmp_path. '/mycode.txt ', ' dummy test ' ); Echo file_get_contents // Would echo dummy test;
If it is two separate PHP files:
a. PHP file_put_contents (Sae_tmp_path. '/mycode.txt ', ' dummy test ' ); b. PHP Echo file_get_contents // error, file no longer exists ...
In this case, you should understand that using it as a cache will not lead to performance gains, but rather to additional overhead.
SAE temp file Read and write example Sae_tmp_path