Custom Option - File Upload:

When uploading a file on a Custom Option of a Product it ends up at:


When you upload a file.jpg, it ends up being renamed into 123kjhkjhkjhdsk.jpg.

What I need:

I need it to be saved in Original Name.

What I have done so far:

Now, I was able to modify \lib\Varien\File\Uploader.php https://github.com/varinen/solvingmagento_1.7.0/blob/master/lib/Varien/File/Uploader.php#L532

static public function getDispretionPath($fileName)
    $dispretionPath = '/orders';

    return $dispretionPath;

to store the files into a different folder.

But I cant find anywhere where the filename is being changed.

Any ideas?

PS: reason for Original Filename is because files uploaded need to be avaliable for download through FTP. So having original name and order # as a folder will solve current requirement.

1 Answer 1


First of all I want to say that you shouldn't use the real name of the file. What if 2 customers upload a file with the same name? The first one will get overwritten.
I suggest you use something like original_file_name_SomeHashHERe.png.
Also don't change the getDispretionPath method from the uploader class.
For 2 reasons: 1. You should never edit the core code. 2. That method is used by multple actions. If you change it it will be changed for all the other actions. You don't want that.

Now a possible solution. The file name is changed in the method Mage_Catalog_Model_Product_Option_Type_File::_validateUploadedFile.
More specific on this line:

$fileHash = md5(file_get_contents($fileInfo['tmp_name']));  

Override the method and change that line.
Also the same method can solve you your dispersion path problem.
The line above the one that changes the file name is

$filePath = $dispersion;

Change $dispersion to what ever you need.

  • Thanks!!! SOLVED! I went over that file before but did not find the hashing line before. Reason for original file name is: all orders will be separated by Order# and Customer Name and also the way these files are going to be uploaded only by the admin. The front-end uploading is already done by another plugin that handles customer uploads to another folder. Oct 27, 2014 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.