contributions/binaries/enabled.inc.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * @defgroup Binaries 00004 * 00005 * Keeps files in the database and manages file uploads 00006 * 00007 * The binaries module introduces a special template that can hold uploaded files 00008 * and make tham accessible to the webbrowser at /binaries/view/{id}. 00009 * 00010 * The module and namely the view action takes care of the uploaded file's 00011 * mime type. It depends on the mime module to handle output. 00012 * 00013 * Uploading a file must be handled by the using application itself. The 00014 * gyro core offers an upload widget that can be used to print the input widget: 00015 * 00016 * @code 00017 * print WidgetInput::output( 00018 * 'fileup', 00019 * 'Choose a file', 00020 * '', // File input does not accept a value! 00021 * WidgetInput::FILE, 00022 * array('accept' => 'image/jpeg') 00023 * ); 00024 * @endcode 00025 * 00026 * @attention 00027 * Note that the enclosing form must have the attribute enctype="multipart/form-data". 00028 * 00029 * The Gyro core internally transforms the $_FILE and associated arrays to 00030 * be included in the PageData post-array. We therefor can write the 00031 * following code: 00032 * 00033 * 00034 * @code 00035 * $fileup = $page_data->get_post()->get_item('fileup'); 00036 * if (Binaries::is_upload($fileup)) { 00037 * $binary = false; 00038 * $err = Binaries::create_from_post($fileup, $binary); 00039 * if ($err->is_ok()) { 00040 * // Binary was created, we can now link to it, e.g. 00041 * } 00042 * } 00043 * @endcode 00044 * 00045 * This will work, even if the user did not upload anything. 00046 * 00047 * If an upload is required, just let create_from_post() do the work: 00048 * 00049 * @code 00050 * $fileup = $page_data->get_post()->get_item('fileup'); 00051 * $binary = false; 00052 * $err = Binaries::create_from_post($fileup, $binary); 00053 * if ($err->is_ok()) { 00054 * // Binary was created, we can now link to it, e.g. 00055 * } 00056 * @endcode 00057 * 00058 * Note that the application should take care of deleting old associations, 00059 * if a new file was uploaded (this will become a new instance with a new id!). 00060 */ 00061 00062 Load::enable_module('mime');