一般情况下,我们可以使用PHP代码动态将数据写入文件或从文件中读取数据,例如以下代码:
写入文件:
$indexNum=rand(1,10000); //随机数做JSON文件名标识
$f = fopen("../json/actPics".$indexNum.".json","w") or die("fail to open"); //生成JSON文件
fwrite($f,$actImgSrc);
fclose($f);
生成的文件目录如图:
读入文件:
$json_arr = file_get_contents("../json/actPics".$actImgFileIndex.".json");
$json_arr=json_decode($json_arr); //json字符串装换成JSON格式
看起来是不是特别的简单,而且很好操纵呢?但是!!!!
在SAE云平台是进制IO文件的读写操作的!!!
不过呢我们也有解决之法的。
上边的程序在SAE云服务平台上是这样的:
将文件写入Storage:
$indexNum=rand(1,10000); //随机数做JSON文件名标识
$f = fopen("saestor://1490814083/json/actPics".$indexNum.".json","w") or die("fail to open"); //生成JSON文件
fwrite($f,$actImgSrc);
fclose($f);
从Storage读取文件:
$json_arr = file_get_contents("saestor://1490814083/json/actPics".$actImgFileIndex.".json");
$json_arr=json_decode($json_arr); //json字符串装换成JSON格式
当然使用Storage之前必须创建Storage,如图是我创建的Storage:
扫描二维码关注公众号,回复:
2662590 查看本文章
生成的文件是这样的:
所以上边的url看懂了吗宝宝们??
注意上边的url:saestor://1490814083/json/