Uploaded image for project: 'In-Portal CMS'
  1. In-Portal CMS
  2. INP-824

Uploaded file distribution within /system/ folder

    XMLWordPrintable

    Details

    • Additional information:
      Hide

      Hashing function for 2c item:

      static function getHashPathForLevel( $name, $levels = 2 ) {
      	if ( $levels == 0 ) {
      		return '';
      	} else {
      		$hash = md5( $name );
      		$path = '';
      		for ( $i = 1; $i <= $levels; $i++ ) {
      			$path .= substr( $hash, 0, $i ) . '/';
      		}
      		return $path;
      	}
      }
      

      Unit config field declaration:

      'DataFile' => Array (
      	'type' => 'string', 'formatter' => 'kUploadFormatter',
      	'max_size' => MAX_UPLOAD_SIZE, // in Bytes !
      	'file_types' => '*.*',
      	'files_description' => '!la_hint_AllFiles!',
      	'upload_dir' => '/system/user_files/', // relative to project's home
      	'as_image' => false,
      	'multiple' => 5, // false or max number of files - will be stored as serialized array of paths
      	'direct_links' => true, // use direct file urls or send files through wrapper (requires mod_mime_magic)
      	'default' => null,
      	'filename_prefix' => 'DATE-TIME-PREFIX-USER', // alpha-numeric symbol or phrase, or reserved words (DATE/TIME/PREFIX/USER) that will be added as a Prefix to filename 
      	'filename_suffix' => 'DATE-TIME-PREFIX-USER', // alpha-numeric symbol or phrase, or reserved words (DATE/TIME/PREFIX/USER) that will be added as an Ending to filename
      	'storage_engine' => STORAGE_ENGINE_NONE (default) or STORAGE_ENGINE_HASH or STORAGE_ENGINE_TIMESTAMP  , // option to specify desired storing engine: _blank_, HASH (2 level sub-folder generated from filename hash), TIMESTAMP (2 level sub-folders as yearmonth/day)   
      )
      
      Show
      Hashing function for 2c item: static function getHashPathForLevel( $name , $levels = 2 ) { if ( $levels == 0 ) { return ''; } else { $hash = md5( $name ); $path = ''; for ( $i = 1; $i <= $levels ; $i ++ ) { $path .= substr( $hash , 0, $i ) . '/' ; } return $path ; } } Unit config field declaration: 'DataFile' => Array ( 'type' => ' string ' , 'formatter' => 'kUploadFormatter' , 'max_size' => MAX_UPLOAD_SIZE, // in Bytes ! 'file_types' => '*.*' , 'files_description' => '!la_hint_AllFiles!' , 'upload_dir' => '/system/user_files/' , // relative to project's home 'as_image' => false , 'multiple' => 5, // false or max number of files - will be stored as serialized array of paths 'direct_links' => true , // use direct file urls or send files through wrapper (requires mod_mime_magic) ' default ' => null , 'filename_prefix' => 'DATE-TIME-PREFIX-USER' , // alpha- numeric symbol or phrase, or reserved words (DATE/TIME/PREFIX/USER) that will be added as a Prefix to filename 'filename_suffix' => 'DATE-TIME-PREFIX-USER' , // alpha- numeric symbol or phrase, or reserved words (DATE/TIME/PREFIX/USER) that will be added as an Ending to filename 'storage_engine' => STORAGE_ENGINE_NONE ( default ) or STORAGE_ENGINE_HASH or STORAGE_ENGINE_TIMESTAMP , // option to specify desired storing engine: _blank_, HASH (2 level sub-folder generated from filename hash), TIMESTAMP (2 level sub-folders as yearmonth/day) )
    • Change Log Message:
      Adding file distributed storage engine
    • Story Points:
      3
    • External issue ID:
      1022
    • Copy Issue Key:
    • Patch Instructions:

      Patches must be submitted through Phabricator.

    • BC Break Details:
      Hide

      Reborn methods:

      • "ImageEventHandler::ValidateFileName" into "FileHelper::ensureUniqueFilename"
      Show
      Reborn methods: "ImageEventHandler::ValidateFileName" into "FileHelper::ensureUniqueFilename"

      Description

      When file uploads are happening a lot on the site, then all files are stored under same /system/... sub-folder. This doesn't pose any problem to webserver to easily access them, however it makes it near to impossible to manage that files manually. Like view/backup/restore individual files, when there are 2000+ files in one directory.

      That's why we are proposing uploaded file distribution engine, that will create sub-folders within target upload folder to store uploaded files. Here are some ideas:

      [b]1. Filenames[/b]

      a. ability to have Prefix (defined in Field declaration (in unit config), default is empty, DATE-TIME which reserved, but can specify any other symbols)

      b. ability to have Ending (defined in Field declaration (in unit config), default is DATE-TIME which reserved, but can specify any other symbols)

      DATE = 20110131 (2011/01/31)
      TIME = 123401 (12:34:01)

      Examples:

      • 20110131-123401_my-custom-filename-whatever.jpg
      • my-custom-filename-whatever_20110131-123401.jpg

      or other combinations

      This will give us full flexibility in filenames

      [b]2. Folders[/b]

      Similar here, give 3 options for each upload field:

      a. As is now - All files go into single specified folder.

      b. Chronological - YEARMONTH / DAY / (adds 2 sub-levels)

      c. Hash - as proposed by Alex (adds 2 sub-levels, see "Additional Information" field for function code)

      [b]NOTE:[/b]
      1. Hashed path will be stored along with a filename, since in case of timestamp-based hashing there is no way to determine hash path to a file by it's name.
      2. All resized versions will be placed without special structure under /resized/ folder.
      3. All code completely/mostly will be located in kUploadFormatter class, so extending that class could give ability to add new storage engine types

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alex Alex
                Reporter:
                alex Alex
                Developer:
                Erik Snarski [Intechnic]
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: