search
Homephp教程php手册SAE的storage服务使用方法

SAE全称是Sina App Engine(简称SAE)是新浪研发中心推出的国内首个公有云计算平台,支持PHP,MySQL,Memcached,Mail,TaskQueue,RDC(关系型数据库集群)等服务,下面我们来看SAE的storage服务用法

今天终于弄懂了sae的storage怎么使用,这里是sae的storage的概述地址:

http://sae.sina.com.cn/doc/php/storage.html。

因为sae不支持文件权限设置,所有的代码文件都是不可数的,但是sae提供了特别好的一个分布式文件存储服务,用来存放持久文件,其实就是用来存放网站的素材文件,如图片,文件等等的,所以,当需要存储文件数据的时候,可以使用使用sae.

使用sae一共有两种方案.

官方提供的一种方案是:使用官方的storage类,直接可以进行文件操作,如存放文件,删除文件,修改文件等等.

官方API文档地址:http://apidoc.sinaapp.com/sae/SaeStorage.html

还有一种方法是我在sae的应用商店看到的,里面有一个合成的wordpress for sae,我们可以看到详细的代码,我现在将自己简单的测试代码贴到下面,只为实现storage,不适用于开发场景,代码如下:

 class="brush:php;"><html> 
	<body> 
	 
	<form action="" method="post" enctype="multipart/form-data"> 
	<label for="file">Filename:</label> 
	<input type="file" name="file" id="file" />  
	<br /> 
	<input type="submit" name="submit" value="Submit" /> 
	</form> 
	 
	</body> 
	</html> 
	 
	<?php 
	 
	$domain = "test"; 
	$upload_dir = "saestor://" . $domain . "/qiao1/2/3/4/5/"; 
	 
	if(!is_dir($upload_dir)) 
	{ 
	 //mkdir($upload_dir , 0777); 
	} 
	 
	if ($_FILES["file"]["error"] > 0) 
	  { 
	  echo "Error: " . $_FILES["file"]["error"] . "<br />"; 
	  } 
	else 
	  { 
	  echo "Upload: " . $_FILES["file"]["name"] . "<br />"; 
	  echo "Type: " . $_FILES["file"]["type"] . "<br />"; 
	  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; 
	  echo "Stored in: " . $_FILES["file"]["tmp_name"]; 
	 
	  } 
	if(move_uploaded_file($_FILES["file"]["tmp_name"],$upload_dir . $_FILES["file"][&#39;name&#39;])) 
	{ 
	 echo &#39;ok&#39;; 
	} 
	 
	 
	//mkdir($upload_dir . &#39;qiao&#39; , 0777); 
	 
	 

我们可以直接使用move_uploaded_file函数将临时文件上传,要注意的是第二个参数$upload_dir=”saestor://” . $domain . “/” . $dir.

其中,$domain就是storage中创建的storage服务名称,$dir就是要存放的目录,如要将文件存放在saestor://mydomain/dir1/dir2/dir3/下,可以直接使用该url,而不需要使用mkdir函数进行创建,因为stotage已经将该目录自动进行了创建.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.