官术网_书友最值得收藏!

Introduction

In addition to robust content editing features, concrete5 comes with a powerful tool to manage static files on your website, called the file manager. The file manager is where you can store any type of static document, including images, videos, PDFs, documents, and audio files. The file manager allows you to create downloadable links to the files, embed photos into your site content, and much more. You can even assign permissions to files inside the file manager to allow for greater control in deciding what files users can download.

Working with files through the concrete5 interface is a delight, but sometimes you will want to integrate the powerful functionality of the file manager into your own custom applications built in concrete5. In this chapter, we will show how to interact with files, upload new files, and even upload new files to the file manager.

A note about the code in this chapter

Much of the code presented in this chapter can go just about anywhere in a concrete5 application. Since we are just going to be trying out simple code snippets, it makes sense to experiment with this code in a sandbox area. There are a few places in concrete5 that make sense for this, but we will be using /config/site_post.php to test out our code.

It is a good idea to erase any experimental and arbitrary code from site_post.php after each recipe, so that your site is ready for the next exercise.

Also, we will need to dump the contents of variables from time to time. Each PHP developer has his or her own way of doing this, but in this chapter we will be using a custom debug function. You may recognize this function from Chapter 1, Pages and Page Types. We will continue using it here, as it makes the output easy to read and saves some time while developing.

Place the following PHP function at the top of /config/site_post.php:

function my_debug($var) {
   echo '<pre>';
   print_r($var);
   echo '</pre>';
   exit;
}

Now we can dump variable contents by calling my_debug($variableName) and see a nicely formatted output of the contents of the variable. Feel free to use print_r or var_dump as an alternative.

Placing debug code in site_post.php is great for experimentation and trying out the concrete5 API, but it will disrupt the regular operation of a concrete5 website. It is recommended that all of the recipes in this chapter be performed on a testing copy of concrete5.

主站蜘蛛池模板: 遵义县| 东阿县| 宿松县| 永定县| 陕西省| 万全县| 玉溪市| 高碑店市| 新建县| 舞阳县| 南部县| 三原县| 唐山市| 乡宁县| 宜兴市| 平阳县| 东宁县| 镇沅| 响水县| 达拉特旗| 平乡县| 子长县| 江门市| 邹平县| 青河县| 崇州市| 托克托县| 浪卡子县| 盱眙县| 南岸区| 丹阳市| 津市市| 唐山市| 长泰县| 延边| 枞阳县| 商水县| 普安县| 东城区| 南康市| 林周县|