Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 636

Přidáno uživatelem Michal Kliment před více než 14 roky(ů)

Oprava chyba - neslo nahravat soubory. Duvod - pro ziskani nastaveni se pozivalo starych metod configu, nyni se pouziva jiz settings (vse se bere z databaze).

Zobrazit rozdíly:

freenetis/trunk/kohana/application/helpers/upload.php
*/
class upload_Core {
public static $mimes = array
(
'7z' => array('application/x-7z-compressed'),
'ai' => array('application/postscript'),
'aif' => array('audio/x-aiff'),
'aifc' => array('audio/x-aiff'),
'aiff' => array('audio/x-aiff'),
'asf' => array('video/x-ms-asf'),
'atom' => array('application/atom+xml'),
'avi' => array('video/x-msvideo'),
'bin' => array('application/octet-stream','application/macbinary'),
'bmp' => array('image/bmp'),
'cab' => array('application/x-cab'),
'cpt' => array('application/mac-compactpro'),
'class' => array('application/octet-stream'),
'css' => array('text/css'),
'csv' => array('text/x-comma-separated-values', 'application/vnd.ms-excel'),
'deb' => array('application/x-debian-package'),
'dbk' => array('application/docbook+xml'),
'dir' => array('application/x-director'),
'dcr' => array('application/x-director'),
'doc' => array('application/msword'),
'dmg' => array('application/x-apple-diskimage'),
'dms' => array('application/octet-stream'),
'dvi' => array('application/x-dvi'),
'dxr' => array('application/x-director'),
'dll' => array('application/octet-stream', 'application/x-msdos-program'),
'eml' => array('message/rfc822'),
'exe' => array('application/x-msdos-program', 'application/octet-stream'),
'eps' => array('application/postscript'),
'gif' => array('image/gif'),
'gtar' => array('application/x-gtar'),
'gz' => array('application/x-gzip'),
'htm' => array('text/html'),
'html' => array('text/html'),
'hqx' => array('application/mac-binhex40'),
'ics' => array('text/calendar'),
'iso' => array('application/x-iso9660-image'),
'jar' => array('application/java-archive'),
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'js' => array('application/x-javascript'),
'json' => array('application/json'),
'lha' => array('application/octet-stream'),
'log' => array('text/plain', 'text/x-log'),
'lzh' => array('application/octet-stream'),
'midi' => array('audio/midi'),
'mid' => array('audio/midi'),
'mif' => array('application/vnd.mif'),
'mp2' => array('audio/mpeg'),
'mp3' => array('audio/mpeg'),
'mov' => array('video/quicktime'),
'movie' => array('video/x-sgi-movie'),
'mpe' => array('video/mpeg'),
'mpeg' => array('video/mpeg'),
'mpg' => array('video/mpeg'),
'mpga' => array('audio/mpeg'),
'msi' => array('application/x-msi'),
'oda' => array('application/oda'),
'odb' => array('application/vnd.oasis.opendocument.database'),
'odc' => array('application/vnd.oasis.opendocument.chart'),
'odf' => array('application/vnd.oasis.opendocument.forumla'),
'odg' => array('application/vnd.oasis.opendocument.graphics'),
'odi' => array('application/vnd.oasis.opendocument.image'),
'odm' => array('application/vnd.oasis.opendocument.text-master'),
'odp' => array('application/vnd.oasis.opendocument.presentation'),
'ods' => array('application/vnd.oasis.opendocument.spreadsheet'),
'odt' => array('application/vnd.oasis.opendocument.text'),
'ogg' => array('application/ogg'),
'otg' => array('application/vnd.oasis.opendocument.graphics-template'),
'oth' => array('application/vnd.oasis.opendocument.web'),
'otp' => array('application/vnd.oasis.opendocument.presentation-template'),
'ots' => array('application/vnd.oasis.opendocument.spreadsheet-template'),
'ott' => array('application/vnd.oasis.opendocument.template'),
'pdf' => array('application/pdf', 'application/x-download'),
'php' => array('application/x-httpd-php'),
'php3' => array('application/x-httpd-php'),
'php4' => array('application/x-httpd-php'),
'php5' => array('application/x-httpd-php'),
'phps' => array('application/x-httpd-php-source'),
'phtml' => array('application/x-httpd-php'),
'png' => array('image/png', 'image/x-png'),
'pps' => array('application/vnd.ms-powerpoint'),
'ppt' => array('application/powerpoint'),
'ps' => array('application/postscript'),
'psd' => array('application/x-photoshop', 'image/x-photoshop'),
'qt' => array('video/quicktime'),
'ra' => array('audio/x-realaudio'),
'ram' => array('audio/x-pn-realaudio'),
'rar' => array('application/rar'),
'rm' => array('audio/x-pn-realaudio'),
'rpm' => array('audio/x-pn-realaudio-plugin', 'application/x-redhat-package-manager'),
'rss' => array('application/rss+xml'),
'rtf' => array('text/rtf'),
'rtx' => array('text/richtext'),
'rv' => array('video/vnd.rn-realvideo'),
'sea' => array('application/octet-stream'),
'shtml' => array('text/html'),
'sit' => array('application/x-stuffit'),
'smi' => array('application/smil'),
'smil' => array('application/smil'),
'so' => array('application/octet-stream'),
'swf' => array('application/x-shockwave-flash'),
'tar' => array('application/x-tar'),
'torrent' => array('application/x-bittorrent'),
'text' => array('text/plain'),
'tif' => array('image/tiff'),
'tiff' => array('image/tiff'),
'tgz' => array('application/x-tar'),
'txt' => array('text/plain'),
'wav' => array('audio/x-wav'),
'wbxml' => array('application/wbxml'),
'wmlc' => array('application/wmlc'),
'wpd' => array('application/vnd.wordperfect'),
'word' => array('application/msword', 'application/octet-stream'),
'xhtml' => array('application/xhtml+xml'),
'xht' => array('application/xhtml+xml'),
'xl' => array('application/excel'),
'xls' => array('application/excel', 'application/vnd.ms-excel'),
'xml' => array('text/xml'),
'xsl' => array('text/xml'),
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed')
);
/**
* Save an uploaded file to a new location.
*
......
$filename = time().$file['name'];
}
if (config::item('upload.remove_spaces') === TRUE)
if (Settings::get('upload_remove_spaces'))
{
// Remove spaces from the filename
$filename = preg_replace('/\s+/', '_', $filename);
......
if ($directory === NULL)
{
// Use the pre-configured upload directory
$directory = config::item('upload.directory', TRUE);
$directory = Settings::get('upload_directory');
}
// Make sure the directory ends with a slash
$directory = rtrim($directory, '/').'/';
if ( ! is_dir($directory) AND config::item('upload.create_directories') === TRUE)
if ( ! is_dir($directory) AND Settings::get('upload_create_directories'))
{
// Create the upload directory
mkdir($directory, 0777, TRUE);
......
// Get the default extension of the file
$extension = strtolower(substr(strrchr($file['name'], '.'), 1));
// Get the mime types for the extension
$mime_types = config::item('mimes.'.$extension);
$mime_types = $mimes[$extension];
// Make sure there is an extension, that the extension is allowed, and that mime types exist
return ( ! empty($extension) AND in_array($extension, $allowed_types) AND is_array($mime_types));
freenetis/trunk/kohana/application/libraries/Form_Upload.php
public function directory($dir = NULL)
{
// Use the global upload directory by default
empty($dir) and $dir = Config::item('upload.upload_directory');
empty($dir) and $dir = Settings::get('upload_directory');
// Make the path asbolute and normalize it
$dir = str_replace('\\', '/', realpath($dir)).'/';
......
// Set the filename to the original name
$filename = $this->upload['name'];
if (Config::item('upload.remove_spaces'))
if (Settings::get('upload_remove_spaces'))
{
// Remove spaces, due to global upload configuration
$filename = preg_replace('/\s+/', '_', $this->data['value']);
......
// Allow nothing by default
$allow = FALSE;
$mimes = array
(
'7z' => array('application/x-7z-compressed'),
'ai' => array('application/postscript'),
'aif' => array('audio/x-aiff'),
'aifc' => array('audio/x-aiff'),
'aiff' => array('audio/x-aiff'),
'asf' => array('video/x-ms-asf'),
'atom' => array('application/atom+xml'),
'avi' => array('video/x-msvideo'),
'bin' => array('application/octet-stream','application/macbinary'),
'bmp' => array('image/bmp'),
'cab' => array('application/x-cab'),
'cpt' => array('application/mac-compactpro'),
'class' => array('application/octet-stream'),
'css' => array('text/css'),
'csv' => array('text/x-comma-separated-values', 'application/vnd.ms-excel'),
'deb' => array('application/x-debian-package'),
'dbk' => array('application/docbook+xml'),
'dir' => array('application/x-director'),
'dcr' => array('application/x-director'),
'doc' => array('application/msword'),
'dmg' => array('application/x-apple-diskimage'),
'dms' => array('application/octet-stream'),
'dvi' => array('application/x-dvi'),
'dxr' => array('application/x-director'),
'dll' => array('application/octet-stream', 'application/x-msdos-program'),
'eml' => array('message/rfc822'),
'exe' => array('application/x-msdos-program', 'application/octet-stream'),
'eps' => array('application/postscript'),
'gif' => array('image/gif'),
'gtar' => array('application/x-gtar'),
'gz' => array('application/x-gzip'),
'htm' => array('text/html'),
'html' => array('text/html'),
'hqx' => array('application/mac-binhex40'),
'ics' => array('text/calendar'),
'iso' => array('application/x-iso9660-image'),
'jar' => array('application/java-archive'),
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'js' => array('application/x-javascript'),
'json' => array('application/json'),
'lha' => array('application/octet-stream'),
'log' => array('text/plain', 'text/x-log'),
'lzh' => array('application/octet-stream'),
'midi' => array('audio/midi'),
'mid' => array('audio/midi'),
'mif' => array('application/vnd.mif'),
'mp2' => array('audio/mpeg'),
'mp3' => array('audio/mpeg'),
'mov' => array('video/quicktime'),
'movie' => array('video/x-sgi-movie'),
'mpe' => array('video/mpeg'),
'mpeg' => array('video/mpeg'),
'mpg' => array('video/mpeg'),
'mpga' => array('audio/mpeg'),
'msi' => array('application/x-msi'),
'oda' => array('application/oda'),
'odb' => array('application/vnd.oasis.opendocument.database'),
'odc' => array('application/vnd.oasis.opendocument.chart'),
'odf' => array('application/vnd.oasis.opendocument.forumla'),
'odg' => array('application/vnd.oasis.opendocument.graphics'),
'odi' => array('application/vnd.oasis.opendocument.image'),
'odm' => array('application/vnd.oasis.opendocument.text-master'),
'odp' => array('application/vnd.oasis.opendocument.presentation'),
'ods' => array('application/vnd.oasis.opendocument.spreadsheet'),
'odt' => array('application/vnd.oasis.opendocument.text'),
'ogg' => array('application/ogg'),
'otg' => array('application/vnd.oasis.opendocument.graphics-template'),
'oth' => array('application/vnd.oasis.opendocument.web'),
'otp' => array('application/vnd.oasis.opendocument.presentation-template'),
'ots' => array('application/vnd.oasis.opendocument.spreadsheet-template'),
'ott' => array('application/vnd.oasis.opendocument.template'),
'pdf' => array('application/pdf', 'application/x-download'),
'php' => array('application/x-httpd-php'),
'php3' => array('application/x-httpd-php'),
'php4' => array('application/x-httpd-php'),
'php5' => array('application/x-httpd-php'),
'phps' => array('application/x-httpd-php-source'),
'phtml' => array('application/x-httpd-php'),
'png' => array('image/png', 'image/x-png'),
'pps' => array('application/vnd.ms-powerpoint'),
'ppt' => array('application/powerpoint'),
'ps' => array('application/postscript'),
'psd' => array('application/x-photoshop', 'image/x-photoshop'),
'qt' => array('video/quicktime'),
'ra' => array('audio/x-realaudio'),
'ram' => array('audio/x-pn-realaudio'),
'rar' => array('application/rar'),
'rm' => array('audio/x-pn-realaudio'),
'rpm' => array('audio/x-pn-realaudio-plugin', 'application/x-redhat-package-manager'),
'rss' => array('application/rss+xml'),
'rtf' => array('text/rtf'),
'rtx' => array('text/richtext'),
'rv' => array('video/vnd.rn-realvideo'),
'sea' => array('application/octet-stream'),
'shtml' => array('text/html'),
'sit' => array('application/x-stuffit'),
'smi' => array('application/smil'),
'smil' => array('application/smil'),
'so' => array('application/octet-stream'),
'swf' => array('application/x-shockwave-flash'),
'tar' => array('application/x-tar'),
'torrent' => array('application/x-bittorrent'),
'text' => array('text/plain'),
'tif' => array('image/tiff'),
'tiff' => array('image/tiff'),
'tgz' => array('application/x-tar'),
'txt' => array('text/plain'),
'wav' => array('audio/x-wav'),
'wbxml' => array('application/wbxml'),
'wmlc' => array('application/wmlc'),
'wpd' => array('application/vnd.wordperfect'),
'word' => array('application/msword', 'application/octet-stream'),
'xhtml' => array('application/xhtml+xml'),
'xht' => array('application/xhtml+xml'),
'xl' => array('application/excel'),
'xls' => array('application/excel', 'application/vnd.ms-excel'),
'xml' => array('text/xml'),
'xsl' => array('text/xml'),
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed')
);
foreach ($types as $type)
{
if (in_array($mime, Config::item('mimes.'.$type)))
if (in_array($mime, $mimes[$type]))
{
// Type is valid
$allow = TRUE;
freenetis/trunk/kohana/application/libraries/Settings.php
private static $use_javascript = 1;
private static $index_page = 1;
private static $email_default_email = 'no-reply@freenetis.org';
private static $upload_directory = 'upload';
private static $upload_remove_spaces = 1;
private static $upload_create_directories = 1;
/**
* @author Michal Kliment
freenetis/trunk/kohana/system/libraries/View.php
// Load the filename and set the content type
$this->kohana_filename = Kohana::find_file('views', $name.'.'.$type, TRUE, $type);
$this->kohana_filetype = Config::item('mimes.'.$type);
$this->kohana_filetype = upload::$mimes[$type];
$this->kohana_filetype = empty($this->kohana_filetype) ? $type : $this->kohana_filetype;
}

Také k dispozici: Unified diff