Custom upload path for a specific file type

  • Posts: 429
  • Thank you received: 19
6 months 2 weeks ago #361231

Hi, I am trying to set a custom upload path for a specific file type such as audio and video files. Can the path be changed for example via

public function onBeforeFileCreate(&$file, &$do) {
$file_check=explode('.',$file->file_path);
if(end($file_check)=='mp3'){
$upload_url='media/com_hikashop/upload/safe/audio/';
}
if(end($file_check)=='mp4'){
$upload_url='media/com_hikashop/upload/safe/video/';
}
}

Please Log in or Create an account to join the conversation.

  • Posts: 82967
  • Thank you received: 13393
  • MODERATOR
6 months 2 weeks ago #361235

Hi,

If you want to do that, the simplest is to directly add your code in the function getPath of the file administrator/components/com_hikashop/classes/file.php
You would have to look in $_REQUEST and $_FILES in order to see what is going on in order to customize the upload folder on the fly. It won't be simple as there are many cases to take into account.

You can't do it with just onBeforeFileCreate. First, onBeforeFileCreate doesn't allow you to do that, and second, even if it did, you not only need to adapt the path on the fly for the upload, but also everywhere where the files are loaded / displayed. The $path function is called everywhere HikaShop needs to add / remove / get files.

Also, note that if you modify directly administrator/components/com_hikashop/classes/file.php you'll loose your changes each time you update HikaShop. So you'll have to reapply them after the update. Ideally, you want to create an override of that file as explained here:
www.hikashop.com/support/documentation/6...ntation.html#classes

The following user(s) said Thank You: neo191987

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum