SAE-Upload local images to the Storagephp version of SAE

WBOY
Release: 2016-08-08 09:22:07
Original
984 people have browsed it

Sina’s SAE is in a security period and does not support SAE that directly uploads local files.


That is, I cannot select a local file through the Select File button. After clicking Submit, the file cannot be successfully submitted to the SAE cloud server. What should I do? ? needs to be implemented through the Storage provided by SAE, and the local files can be uploaded through the API interface of SotrageSAE Storage, then Then access the files in Storage to achieve this effect! !


The following is a step-by-step explanation through pictures:

1. Open our SAE application and you can see storage in the service management here


2. Then click storage to enter and you will see the following interface

3. Click to create a new domain with a random name. This domain will be used to store the files we upload in the future. After creating it, you can click domain management to view what we have created. The domain

4. Everything is ready. Now we just need to write a program to store data in this domain. I use PHP language, and the principle is the same for other languages!

<?php 

// 当用户点击submit提交上传的文件时
if(isset($_POST["submit"])){
	// 创建SAE storage存储
	$storage= new SaeStorage();// 创建SAE storage存储对象
	$domain = &#39;kepuna&#39;;// 这里的$domain对应得名字就是自己起的名字
	
	$fileType = $_FILES["file"]["type"]; //被上传文件的类型

	if(($fileType=="image/gif") || ($fileType=="image/jpeg")||($fileType=="image/jpg")||($fileType=="image/png")){
	
	if($storage->fileExists($domain,$filename) == true) {// 判断文件是否已经存在
        echo "<p style=&#39;background:#FCC9C4;border-radius: 0.3em;padding:5px;color:#fff;&#39;&#39;>图片已存在,请重新上传!</p>";
        }
	else{
		
	$filename = $_FILES["file"]["name"];
	$storage->upload( $domain,$filename,$_FILES[file][tmp_name]); 

        echo "<p style=&#39;background:#7CBD55;border-radius: 0.3em;padding:5px;color:#fff;&#39;>图片上传成功!</p>";
        echo "<script> window.location='showImage.php';</script>";
           
<span style="white-space:pre">	</span>}
    }else{
    	echo "<p style=&#39;background:#FCC9C4;border-radius: 0.3em;padding:5px;color:#fff;&#39;&#39;>图片格数不正确,上传失败!</p>";
    }

}

?>

<!DOCTYPE HTML>
<html>
<head>
	<title></title>
	<meta charset="utf-8" />
	<meta name="viewport" c
	<link href="./css/style.css" rel="stylesheet" type="text/css"  media="all" />	
	
</head>
<body>
		

<form method="POST" enctype="multipart/form-data" class="uploadImageForm">
	<input type="file" name="file" id="file" />
	<input type="submit" value="Submit" name="submit"/>	
</form>

</body>
</html>
Copy after login

Look at the renderings: if there is a bit of a lag, you can try the code and run it on your own machine



How do we pass the program? How about accessing this picture we stored in domain?

The next is the content of showImage.php

<?php

$sae_storage = new SaeStorage();
$domainName = "kepuna";
$listArray = $sae_storage->getList($domainName);
        
foreach($listArray as $image){
    echo "<img src=&#39;http://hjmshop-kepuna.stor.sinaapp.com/$image&#39;/>";

}

?>
Copy after login


There are many methods, this is just one of them, you can refer to

http: //apidoc.sinaapp.com/class-SaeStorage.html You can explore this SAE official document yourself, it’s very simple!

The following are all the pictures in my domain

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces SAE-upload local images to the Storagephp version of SAE, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!