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

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.

主站蜘蛛池模板: 清河县| 郸城县| 肥城市| 恩施市| 陇川县| 台东县| 巴林右旗| 社会| 丹东市| 遂平县| 芦山县| 建德市| 新疆| 鹿邑县| 马龙县| 蒲江县| 都安| 宁晋县| 新巴尔虎左旗| 平乐县| 江山市| 西畴县| 东辽县| 西乌| 海淀区| 江津市| 黔西| 沂水县| 始兴县| 海城市| 彝良县| 凭祥市| 油尖旺区| 嘉鱼县| 霍山县| 华容县| 天台县| 呼图壁县| 收藏| 济南市| 连州市|