Ticket #248 (closed enhancement: fixed)

Opened 15 months ago

Last modified 12 months ago

QfileAsset - introduction to $strRandomFileName

Reported by: voyager123bg Owned by: somebody
Priority: minor Milestone: 1.1
Component: QForms Version: 1.0.0 Stable
Keywords: QfileAssetBase Cc:

Description

I've noticed the following code (lines 95-98) in QfileAssetBase?

 // Save the File in a slightly more permanent temporary location 
$strTempFilePath = $this->strTemporaryUploadPath . '/' . basename($this->dlgFileAsset->flcFileAsset->File) . rand(1000, 9999) . '.' . $strExtension;
copy($this->dlgFileAsset->flcFileAsset->File, $strTempFilePath); 
$this->File = $strTempFilePath;

What I'm proposing is to introduce new string in the QfileAssetBase? - $strRandomFileName

so the code becomes:

// Save the File in a slightly more permanent temporary location 
$strRandomFileName = basename($this->dlgFileAsset->flcFileAsset->File) . rand(1000, 9999) . '.' . $strExtension;
$strTempFilePath = $this->strTemporaryUploadPath . '/' . $strRandomFileName;                        
copy($this->dlgFileAsset->flcFileAsset->File, $strTempFilePath);

  $this->File = $strTempFilePath;

Also, $strTempFilePath should be included in the beginning of QFileAssetBase.

At the end of the day, we will have access to the randomly-generated file name (by Qcubed). I will make it to a patch and submit it for your review.

Attachments

QFileAssetBase.strRandomFileName.patch (1.7 kB) - added by voyager123bg 15 months ago.
introducing strRandomFileName in QFileAssetBase

Change History

Changed 15 months ago by voyager123bg

introducing strRandomFileName in QFileAssetBase

Changed 15 months ago by alex94040

  • status changed from new to in_QA

Voyager, can you talk a little bit about the intent behind this patch? What scenario is it meant to achieve?

Changed 15 months ago by voyager123bg

The possible uses of this is for when you want to allow users to upload files, and wish to alter the filenames so that they are random and unique. I thought when Qcube does this already, why should I write custom algorithm for this kind of task? I searched in the code and saw that it was hard-coded... maybe there is some idea behind it to be made that way? Anyway, I proceeded with the following change and was able to modify it to suit my needs.

An example use of this would be:

$this->fileControl = new QFileAsset($this);

... /as in example/

in btnSave_Click():

if ($this->fileControl->RandomFileName) {
                $this->txtFileName->Text = $this->fileControl->RandomFileName; //fills in the "txtFile" box with the random filename
                copy($this->fileControl->File, __DOCROOT__ . __GALLERY_DIRECTORY__ . '/' . $this->fileControl->RandomFileName);
            }

...

Changed 15 months ago by VexedPanda

I would guess that this ends up being enough for random uploads, but at the point you need to use it in your app, you should probably be doing more to ensure the filename is unique and easily findable again, such as using a DB id, or moving each user's pictures into their own directory.

Changed 15 months ago by VexedPanda

  • milestone changed from 1.0.1 to 1.1

This is not a bugfix, moving to 1.1

Changed 12 months ago by MikeHostetler

  • status changed from in_QA to closed
  • resolution set to fixed

(In [478]) Fixes #248, code by voyager123bg, review by Mike Hostetler

Note: See TracTickets for help on using tickets.