Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Help with fUpload

posted by alex 9 years ago

Hello. I'm not very good with PHP, but need to make some stuff: uploaded file must be randomly renamed with saving of extension and then I need to get this new name in variable.

I try:

$random = fCryptography::randomString(14, 'alphanumeric'); 
$extension = fFile::getExtension($file); 
$file = $uploader->move($dir, 'file')->rename($random . $extension, FALSE);

But get: Fatal error: Using $this when not in object context in ***
inc
flourish
fFile.php on line 787

My guess is that it's because you're accessing the getExtension method the static way while you should initiate the class:

$random    = fCryptography::randomString(14, 'alphanumeric'); 
$fFile     = new fFile($file);
$extension = $fFile->getExtension(); 
$file = $uploader->move($dir, 'file')->rename($random . $extension, FALSE);
posted by earth 9 years ago

no, it doesn't work this way...

move() function return fFile object and I need to get it extension before rename(), but don't know how to...

posted by alex 9 years ago

Check out the code example in ticket #442

posted by wbond 9 years ago

Works like a charm :] Thanks

But now I have another strange problem. I have this in config file:

$uploader->setMIMETypes(
    array(
        'application/x-rar-compressed',
        'application/zip',
		'application/x-7z-compressed',
     // 'application/exe',
        'text/plain',
        'application/x-bittorrent'
    ),
    'Uploaded file type is forbidden'
);

Everything (rar, zip, txt, 7z) is ok but .torrent file still doesnt recognized as "application/x-bittorrent" mime-type while I upload file. I check Apache config and application/x-bittorrent already linked with torrent file type, so I'm unsure if it's Flourish bug or Apache bug.

posted by alex 9 years ago

fFile does custom mime-type detection and does not rely on any third party tools. I doubt I have any rules to check for x-bittorrent. I'd need to know information about the file format so that it can be detected properly.

posted by wbond 9 years ago