Content websites such as news and media publish a lot of text content. If it is stored directly in the database, it will occupy a very large amount of database. The same website also has a lot of picture resources, which takes up a lot of server space resources. So consider saving the content elsewhere and save the saved address into the article field of the database. This reduces the usage of the database, saves the pictures in the cloud disk, and references them from the cloud disk, thereby saving server hard disk space.
News, media and other content websites publish a lot of text content. If they are stored directly in the database, the database will be very large. The same website also has a lot of image resources, which takes up a lot of server space resources. So consider saving the content elsewhere and save the saved address into the article field of the database. This reduces the occupation of the database, saves the pictures in the cloud disk, and references them from the cloud disk, thereby saving server hard disk space.
The main idea of this article is to separate the images that occupy server resources and the article content that occupies database resources from the server, save them to Alibaba Cloud OSS, and then return the save address in Alibaba Cloud and save them to the database. When using it, take out the pictures and data directly according to the path of Alibaba Cloud.
The implementation process is as shown below:
Implementation steps:
1. Obtain the Access Key ID and Access Key Secret of Alibaba Cloud OSS. (The price of Alibaba Cloud OSS 40G cloud disk is 9 yuan per year, which is very cost-effective).
Log in to the Alibaba Cloud user management system: https://ak-console.aliyun.com/#/accesskey, and obtain the appkey and appsecret parameters on the following interface.
2. Create a bucket and set the properties to public read and write permissions. And obtain the OSS external domain name of the bucket, as shown below:
3. Download the SDK file package of Alibaba Cloud OSS, download address: www.zixuephp.cn/xxxxxx. Configure the SDK file package Alioss folder to ThinkPHP's /ThinkPHP/Extend/Vendor/ folder.
4. Configure the obtained Alibaba Cloud OSS parameters Access Key ID and Access Key Secret into the project's config.php file. The configured parameters are as follows:
5. Define Alibaba Cloud operation functions in the common function file common.php under the common folder: including functions for instantiating OSS objects, uploading images to Alibaba Cloud, deleting objects in Alibaba Cloud, and obtaining object paths in Alibaba Cloud. , object upload Alibaba Cloud function. The picture shows the method of instantiating Alibaba Cloud OSS:
6. After submitting data from the background add content page, the Action processing method and saving to the database are as follows:
7. In the front-end page, retrieve the Alibaba Cloud storage path of the content from the database, parse the content corresponding to the path, and display it in the front-end as follows:
These are the entire steps to save published graphic content to Alibaba Cloud.
The article is reproduced from: Self-study PHP blog http://www.zixuephp.cn
Download the source program code address of this case: http://t.cn/RVxAgUW

了解Python编程的入门级代码示例Python是一种简单易学,功能强大的编程语言。对于初学者来说,了解Python编程的入门级代码示例是非常重要的。本文将为您提供一些具体的代码示例,帮助您快速入门。打印HelloWorldprint("HelloWorld")这是Python中最简单的代码示例。print()函数用于将指定的内容输出

PHP变量存储程序运行期间的值,对于构建动态且交互式的WEB应用程序至关重要。本文将深入探讨php变量,并通过10个真实的示例展示它们的实际应用。1.存储用户输入$username=$_POST["username"];$passWord=$_POST["password"];此示例从表单提交中提取用户名和密码,并将其存储在变量中以供进一步处理。2.设置配置值$database_host="localhost";$database_username="username";$database_pa

标题:从入门到精通:Go语言中常用数据结构的代码实现数据结构在编程中起着至关重要的作用,它是程序设计的基础。在Go语言中,有许多常用的数据结构,掌握这些数据结构的实现方式对于成为一名优秀的程序员至关重要。本文将介绍Go语言中常用的数据结构,并给出相应的代码示例,帮助读者从入门到精通这些数据结构。1.数组(Array)数组是一种基本的数据结构,是一组相同类型

如何使用PHP编写库存管理系统中的库存分仓管理功能代码库存管理是许多企业中不可或缺的一部分。对于拥有多个仓库的企业来说,库存分仓管理功能尤为重要。通过合理管理和跟踪库存,企业可以实现不同仓库之间的库存调拨,优化运营成本,改善协同效率。本文将介绍如何使用PHP编写库存分仓管理功能的代码,并为您提供相关的代码示例。一、建立数据库在开始编写库存分仓管理功能的代码之

Java冒泡排序最简单的代码示例冒泡排序是一种常见的排序算法,它的基本思想是通过相邻元素的比较和交换来将待排序序列逐步调整为有序序列。下面是一个简单的Java代码示例,演示了如何实现冒泡排序:publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

《Go语言编程实例:Web开发中的代码示例》随着互联网的快速发展,Web开发已经成为各行业中必不可少的一部分。作为一门功能强大且性能优越的编程语言,Go语言在Web开发中越来越受到开发者们的青睐。本文将通过具体的代码示例,介绍如何利用Go语言进行Web开发,让读者能够更好地理解和运用Go语言来构建自己的Web应用。1.简单的HTTP服务器首先,让我们从一个

华为云边缘计算对接指南:Java代码示例快速实现接口随着物联网技术的快速发展和边缘计算的兴起,越来越多的企业开始关注边缘计算的应用。华为云提供了边缘计算服务,为企业提供了高可靠的计算资源和便捷的开发环境,使得边缘计算应用更加容易实现。本文将介绍如何通过Java代码快速实现华为云边缘计算的接口。首先,我们需要准备好开发环境。确保你已经安装了Java开发工具包(

Java选择排序法代码编写指南及示例选择排序是一种简单直观的排序算法,其思想是每次从未排序的元素中选择最小(或最大)的元素进行交换,直到所有元素排序完成。本文将提供选择排序的代码编写指南,并附上具体的Java示例代码。算法原理选择排序的基本原理是将待排序数组分为已排序和未排序两部分,每次从未排序部分选择最小(或最大)的元素,将其放到已排序部分的末尾。重复上述


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
