Home Backend Development PHP Tutorial SAE-Upload local images to the Storagephp version of SAE

SAE-Upload local images to the Storagephp version of SAE

Aug 08, 2016 am 09:22 AM
html http nbsp

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.

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

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles