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? ?
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 = 'kepuna';// 这里的$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: 0.3em;padding:5px;color:#fff;''>图片已存在,请重新上传!</p>"; } else{ $filename = $_FILES["file"]["name"]; $storage->upload( $domain,$filename,$_FILES[file][tmp_name]); echo "<p style='background:#7CBD55;border-radius: 0.3em;padding:5px;color:#fff;'>图片上传成功!</p>"; echo "<script> window.location='showImage.php';</script>"; <span style="white-space:pre"> </span>} }else{ echo "<p style='background:#FCC9C4;border-radius: 0.3em;padding:5px;color:#fff;''>图片格数不正确,上传失败!</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>
Look at the renderings: if there is a bit of a lag, you can try the code and run it on your own machine
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='http://hjmshop-kepuna.stor.sinaapp.com/$image'/>"; } ?>
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.