Home « Server software «
Documentation: files/files.php
Class Files - The database abstraction layer for files
Files are saved into the file system of the web server. Each file also has a related record in the database.This script is a reference file of this system.
Voir aussi:
- MIME Reference
- File Format Names for New OASIS Open Office XML Format
- MIME Type Settings for Windows Media Services
Licence: GNU Lesser General Public License
Auteurs:
- Bernard Paques bernard.paques@bigfoot.com
- Florent
- GnapZ
Testeurs:
- Geasm
- Mat0806
- Olivier
Reste à faire:
- add a flag to obsolete files
delete() - Delete one file in the database and in the file system
function delete($id)
- $id - the id of the file to delete
- returns an error message, if any
delete_for_anchor() - Delete all files for a given anchor
function delete_for_anchor($anchor)
- $anchor - the anchor to check
- returns an error message, if any
get() - Get one file by id
function &get($id)
- $id - int the id of the file
- returns the resulting $row array, with at least keys: 'id', 'title', 'description', etc.
get_by_anchor_and_name() - Get one file by anchor and name
function &get_by_anchor_and_name($anchor, $name)
- $anchor - string the anchor
- $name - string the file name
- returns the resulting $row array, with at least keys: 'id', 'title', 'description', etc.
get_icon_url() - Get the url to the icon for this file
function get_icon_url($name)
- $name - string the file name
- returns an anchor to the viewing script
get_mime_type() - Get the mime type for a file
function get_mime_type($name)
- $name - string the file name
- returns a string describing the MIME type
get_mime_types() - Get supported MIME types
function &get_mime_types()
- returns array describing supported MIME types ($extension1 => $mime_type1, $extension2 => $mime_type2, ...)
Voir aussi:
- http://www.iana.org/assignment...es/application/
- File Extensions reference
- MIME Types and Extensions for OpenDocument Documents
- Web server MIME types required for serving Flash movies
get_next_url() - Get url of next file
function get_next_url($item, $anchor, $order='date', $capability='?')
- $item - array the current item
- $anchor - string the anchor of the current item
- $order='date' - string the order, either 'date' or 'title'
- $capability='?' - string surfer actual capability ('?', 'M', or 'A')
- returns some text
Voir aussi:
get_previous_url() - Get url of previous file
function get_previous_url($item, $anchor, $order='date', $capability='?')
- $item - array the current item
- $anchor - string the anchor of the current item
- $order='date' - string the order, either 'date' or 'title'
- $capability='?' - string surfer actual capability ('?', 'M', or 'A')
- returns some text
Voir aussi:
get_url() - Get the url to view a file
function get_url($id, $action='view')
- $id - int the id of the file to view
- $action='view' - string the expected action ('view', 'edit', 'delete', ...)
- returns an anchor to the viewing script
files/view.php?id=512
'),
which may be not processed correctly by search engines.
If the parameter 'with_friendly_urls
' has been set to 'Y
' in the configuration panel,
this function will return an URL parsable by search engines (e.g. 'files/view.php/512
').Voir aussi:
increment_hits() - Set the hits counter - errors are not reported, if any
function increment_hits($id)
- $id - the id of the file to update
is_audio_stream() - Look for potential audio streams
function is_audio_stream($name)
- $name - string file name, including extension
- returns TRUE or FALSE
This function returns TRUE for following file types:
- aif audio/aiff
- aiff audio/aiff
- au
- mp2 audio
- mp3 audio
- ra real audio
- snd audio/basic
- wav
- wma audio/x-ms-wma
is_authorized() - Check if a file type is authorized
function is_authorized($name)
- $name - string file name, including extension
- returns TRUE or FALSE
Voir aussi:
is_stream() - Should this file be streamed?
function is_stream($name)
- $name - string file name, including extension
- returns TRUE or FALSE
is_video_stream() - Look for potential video streams
function is_video_stream($name)
- $name - string file name, including extension
- returns TRUE or FALSE
This function returns TRUE for following file types:
- asf
- avi
- divx
- mov
- mp4
- mpe
- mpeg
- mpg
- wmv audio/x-ms-wmv
list_by_date() - List newest files
function &list_by_date($offset=0, $count=10, $variant='dates')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1 - default is 0
- $count=10 - int the number of items to display - default is 10
- $variant='dates' - string the list variant, if any - default is 'dates'
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
// side bar with the list of most recent files
include_once 'files/files.php';
$local['title_en'] = 'Most recent Files';
$local['title_fr'] = 'Fichiers récents';
$title = i18n::user('title');
$items = Files::list_by_date(0, 10);
$text = Skin::build_list($items, 'compact');
$context['text'] .= Skin::build_box($title, $text, 'navigation');
You can also display the newest file separately, using
Files::get_newest()
In this case, skip the very first file in the list by using
Files::list_by_date(1, 10)
list_by_date_for_anchor() - List newest files for one anchor
function &list_by_date_for_anchor($anchor, $offset=0, $count=20, $variant='no_anchor', $capability='?')
- $anchor - int the id of the anchor
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=20 - int the number of items to display
- $variant='no_anchor' - string the list variant, if any
- $capability='?' - string actual surfer capability ('?', 'M', or 'A')
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
Example: include_once 'files/files.php'; $items = Files::list_by_date_for_anchor('section:12', 0, 10); $context['text'] .= Skin::build_list($items, 'compact');
Voir aussi:
- articles/fetch_as_msword.php
- articles/print.php
- articles/view.php
- files/feed.php
- files/fetch_all.php
- sections/print.php
- sections/view.php
- categories/print.php
- categories/view.php
- users/print.php
- users/view.php
list_by_date_for_author() - List newest files for one author
function &list_by_date_for_author($author_id, $offset=0, $count=20, $variant='no_author')
- $author_id - int the id of the author of the file
- $offset=0 - int the offset from the start of the list; usually, 0 or 1 - default is 0
- $count=20 - int the number of items to display - default is 20
- $variant='no_author' - string the list variant, if any - default is 'no_author'
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
list_by_hits() - List most read files
function &list_by_hits($offset=0, $count=10, $variant='hits')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1 - default is 0
- $count=10 - int the number of items to display - default is 10
- $variant='hits' - string the list variant, if any - default is 'hits'
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
Example: include_once '../files/files.php'; $context['text'] .= Skin::build_list(Files::list_by_hits(), 'compact');
You can also display the most read file separately, using Files::get_most_read() In this case, skip the very first file in the list by using Files::list_by_hits(1)
list_by_hits_for_author() - List newest files for one author
function &list_by_hits_for_author($author_id, $offset=0, $count=10, $variant='hits')
- $author_id - int the id of the author of the file
- $offset=0 - int the offset from the start of the list; usually, 0 or 1 - default is 0
- $count=10 - int the number of items to display - default is 10
- $variant='hits' - string the list variant, if any - default is 'hits'
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
list_by_oldest_date() - List oldest files
function &list_by_oldest_date($offset=0, $count=10, $variant='full')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1 - default is 0
- $count=10 - int the number of items to display - default is 10
- $variant='full' - string the list variant, if any - default is 'full'
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
list_by_size() - List biggest files
function &list_by_size($offset=0, $count=10, $variant='full')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=10 - int the number of items to display
- $variant='full' - string the list variant, if any
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
list_by_title_for_anchor() - List files by title for one anchor
function &list_by_title_for_anchor($anchor, $offset=0, $count=10, $variant='no_anchor', $capability='?')
- $anchor - int the id of the anchor
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=10 - int the number of items to display
- $variant='no_anchor' - string the list variant, if any
- $capability='?' - string actual surfer capability ('?', 'M', or 'A')
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
Voir aussi:
- articles/fetch_as_msword.php
- articles/print.php
- articles/view.php
- sections/print.php
- sections/view.php
- categories/print.php
- categories/view.php
list_selected() - List selected files
function &list_selected(&$result, $layout='compact', $capability='?')
- &$result - resource result of database query
- $layout='compact' - string 'full', etc or object, i.e., an instance of Layout_Interface
- $capability='?' - string '?' or 'A', to support editors and to impersonate associates, where applicable
- returns an array of $url => ($prefix, $label, $suffix, $icon)
- 'compact' - to build short lists in boxes and sidebars (this is the default)
- 'hits' - short lists with hits information
- 'dates' - short lists with dates information
- 'no_anchor' - to build detailed lists in an anchor page
- 'no_author' - to build detailed lists in a user page
- 'full' - include anchor information
- 'references' - an array of $id => $name, for building archive files
- 'search' - include anchor information
Voir aussi:
list_unused() - List less downloaded files
function &list_unused($offset=0, $count=10, $variant='full')
- $offset=0 - int the offset from the start of the list; usually, 0 or 1 - default is 0
- $count=10 - int the number of items to display - default is 10
- $variant='full' - string the list variant, if any - default is 'hits'
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
post() - Post a new file or an updated file
function post($fields, $capability='?')
- $fields - array an array of fields
- $capability='?' - string to support editors -- see files/edit.php
- returns the id of the new article, or FALSE on error
Voir aussi:
search() - Search for some keywords in all files
function &search($pattern, $offset=0, $count=10, $variant='search')
- $pattern - the search string
- $offset=0 - int the offset from the start of the list; usually, 0 or 1
- $count=10 - int the number of items to display
- $variant='search' - string the list variant, if any
- returns NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $icon)
- file is visible (active='Y')
- file is restricted (active='R'), but surfer is a logged user
- file is restricted (active='N'), but surfer is an associate
setup() - Create tables for files
function setup()
stat() - Get some statistics for all files
function &stat()
- returns the resulting ($count, $oldest_date, $newest_date, $total_size) array
Voir aussi:
stat_for_anchor() - Get some statistics for one anchor
function &stat_for_anchor($anchor, $capability='?')
- $anchor - the selected anchor (e.g., 'article:12')
- $capability='?' - string actual surfer capability ('?', 'M', or 'A')
- returns the resulting ($count, $oldest_date, $newest_date, $total_size) array