search
HomeBackend DevelopmentPHP TutorialSAE-上传本map片到SAE的Storage(php版)

SAE-上传本地图片到SAE的Storage(php版)

新浪的SAE处于安全期间,不支持直接将本地文件上传的SAE。


 

也就是无法通过选择文件按钮选择本地的文件,点击提交之后,文件不能成功提交到SAE云服务器的,那怎么办哪??需要通过SAE提供的Storage来实现,通过SotrageAPI接口将本地文件上传的SAEStorage,然后再通过访问Storage里的文件来实现这一效果!!


下面通过图片来一步步解说:

1. 打开我们的SAE应用在服务管理这里可以看到storage


 

2. 然后点击storage进去之后看到下面界面

 

3. 点击新建domain名字随便起,这个domain用来存放将来我们上传的文件,创建好之后可以点击domain管理查看我们创建的domain

 

 

4. 一切具备,现在只欠我们通过写程序往这domain里存放数据了,本人用的是php语言,其他语言原理也一样!

 

 

<?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="'background:#FCC9C4;border-radius:">图片已存在,请重新上传!</p>";        }	else{			$filename = $_FILES["file"]["name"];	$storage->upload( $domain,$filename,$_FILES[file][tmp_name]);         echo "<p style="'background:#7CBD55;border-radius:">图片上传成功!</p>";        echo "<script> window.location=&#39;showImage.php&#39;;</script>";           <span style="white-space:pre">	</span>}    }else{    	echo "<p style="'background:#FCC9C4;border-radius:">图片格数不正确,上传失败!</p>";    }}?>	<title></title>	<meta charset="utf-8">	<meta name="viewport" content="width=device-width,initial-scale=1">	<link href="./css/style.css" rel="stylesheet" type="text/css" media="all">				

看下效果图:有点卡大家可以把代码考自己机子上运行下



我们怎么通过程序访问这个我们存放进domain里的图片那?

接下来是showImage.php的内容

<?php $sae_storage = new SaeStorage();$domainName = "kepuna";$listArray = $sae_storage->getList($domainName);        foreach($listArray as $image){    echo "<img  src="/static/imghwm/default1.png" data-src="/img/2015/06/28/2045091017.gif" class="lazy" alt="SAE-上传本map片到SAE的Storage(php版)" >";}?>


方法还有很多种,我这只是其中一种,可以参考

http://apidoc.sinaapp.com/class-SaeStorage.html 这个SAE的官方文档大家自己摸索下,很简单!

下面是我domain中的所有图片

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
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor