Upload file to joomla module

I searched for this for quite a while, but could not find a solution that fits my needs. I am developing a module for Joomla 2.5. I need functionality that allows users to load images / any type of file from the backend in the module configuration.

Question: How to add a file upload field to the joomla module.

Thanks!

+6
source share
2 answers

Just a sample from joomla docs:

<?php //Retrieve file details from uploaded file, sent from upload form $file = JRequest::getVar('file_upload', null, 'files', 'array'); //Import filesystem libraries. Perhaps not necessary, but does not hurt jimport('joomla.filesystem.file'); //Clean up filename to get rid of strange characters like spaces etc $filename = JFile::makeSafe($file['name']); //Set up the source and destination of the file $src = $file['tmp_name']; $dest = JPATH_COMPONENT . DS . "uploads" . DS . $filename; //First check if the file has the right extension, we need jpg only if ( strtolower(JFile::getExt($filename) ) == 'jpg') { if ( JFile::upload($src, $dest) ) { header("Location: http://".$_SERVER["HTTP_HOST"]."/administrator"); Redirect to a page of your choice } else { echo "error !"; //Redirect and throw an error message } } else { echo "Wrong extension !"; //Redirect and notify user file is not right extension } ?> 

More information and complete example (s): http://docs.joomla.org/How_to_use_the_filesystem_package

+7
source

Keep in mind that your HTML form should include

enctype="multipart/form-data"

otherwise, you will not get any result using the joomla function!

+6
source

Source: https://habr.com/ru/post/917286/


All Articles