Home >Backend Development >PHP Tutorial >How to use SAE's storage service_PHP tutorial

How to use SAE's storage service_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:16:541019browse

How to use SAE’s storage service

Today I finally understood how to use SAE’s storage service.

Because sae does not support file permission settings, all code files are uncountable. But sae provides a particularly good distributed file storage service for storing persistent files. In fact, it is used to store the material files of the website, such as pictures, documents, etc.

So, when you need to store file data, you can use sae.

There are two options for using sae.

One of the official solutions is:

Using the official storage class, you can directly perform file operations, such as storing files, deleting files, modifying files, etc.

There is another method that I saw in the sae app store. There is a synthesized wordpress for sae.

We can see the detailed code. I will paste my simple test code below: (only for storage implementation, not suitable for development scenarios)

 代码如下  


 


 




 


 

$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"] . "
";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "
";
  echo "Type: " . $_FILES["file"]["type"] . "
";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
 
  }
if(move_uploaded_file($_FILES["file"]["tmp_name"],$upload_dir . $_FILES["file"]['name']))
{
 echo 'ok';
}
 
 
//mkdir($upload_dir . 'qiao' , 0777);
 
?>

We can directly use the move_uploaded_file function to upload temporary files. What should be noted is the second parameter $upload_dir=”saestor://” . $domain . “/” . $dir.

Wherein, $domain is the name of the storage service created in storage. $dir is the directory to be stored.

If you want to store the file under saestor://mydomain/dir1/dir2/dir3/. You can use the url directly without using the mkdir function to create it, because stockage has automatically created the directory.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/895551.htmlTechArticleHow to use SAE’s storage service Today I finally understood how to use SAE’s storage service. Because sae does not support file permission settings, all code files are uncountable. But sae provides special...
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