Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload in joomla module

Tags:

module

joomla

I have been searching this for quite a while but couldn't find a solution to match my need. I am developing a module for Joomla 2.5 . I need functionality to allow users to upload images/any file type from the backend in module configuration.

Question : How can I add field for file upload in joomla module.

Thanks!

like image 819
Akshat Goel Avatar asked Jun 03 '12 09:06

Akshat Goel


People also ask

How do I upload a large file to Joomla?

After logging into the Administration area (the back end) of your site, go to the Media Manager. To change this size limit, click on the "Options" button in the toolbar. Inside the "Media Manager Options" area, locate the "Maximum Size (in MB)" option, and change the upload limit to what you'd like.

How do I create a folder in Joomla?

To create a folder, click on the "Create Folder" button. Enter a name for the folder, but it is important not to have any spaces in the folder's name. This could cause issues calling the folder in the future. Click the second "Create Folder" button after you've titled the folder.


2 Answers

Just a sample from the 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
}

?>

For more detailed information and full example(s): http://docs.joomla.org/How_to_use_the_filesystem_package

like image 150
HamZa Avatar answered Dec 04 '22 22:12

HamZa


Keep in mind that your HTML form must include

enctype="multipart/form-data"

otherwise you will not get any result with the joomla function!

like image 30
BastianW Avatar answered Dec 04 '22 21:12

BastianW