Image storing for a component

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
NeoAnderson1982
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Aug 01, 2007 3:32 pm

Image storing for a component

Postby NeoAnderson1982 » Wed Aug 01, 2007 3:45 pm

Hi out there.
I'm new developping for Joomla!. I use the 1.5 RC.
I'm writing a component - after having looked at your MVC-Tutz I understand a lot but not everything.
I'm wondering where and how I can store imaged a user has chosen in a form.
The Component is an (volleyball-)exercise-look up-and-store-component which can help trainers to develop a training...
Registered users shall add exercises to the db and they can use therefor a form.
Every exercise shall be able to hold up to three images.
And now I'm wondering how I can upload them (in a directory) or how to store them in the db.
Greetz and thanks
Aljoscha Peters

User avatar
Jomo77
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Tue Jul 24, 2007 3:03 pm

Re: Image storing for a component

Postby Jomo77 » Thu Aug 02, 2007 2:37 pm

Hi Aljoscha,

i have the same problem - did you find a Solution?

I thought about using the mediamanager for uploading the pictures.

And just save the link to the image.

Dave

NeoAnderson1982
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Aug 01, 2007 3:32 pm

Re: Image storing for a component

Postby NeoAnderson1982 » Thu Aug 02, 2007 3:10 pm

No, sry. I haven't think about it so far. The directory of the MediaManager (or maybe /images/comp_name) is a possibility. Let me think about it the next two days. I will post you when I'm done with this part of my comp.
I haven't find a function for uploading an image (or other) file. Maybe someone can help how to do this with the J!-API. Otherwise I must go to php-roots  :(
Last edited by NeoAnderson1982 on Thu Aug 02, 2007 3:34 pm, edited 1 time in total.

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4785
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Image storing for a component

Postby ianmac » Thu Aug 02, 2007 7:21 pm

Look at the com_installer component as an exmaple, or the com_media component to see how they do it.

Ian

NeoAnderson1982
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Aug 01, 2007 3:32 pm

Re: Image storing for a component

Postby NeoAnderson1982 » Fri Aug 03, 2007 10:43 am

Hey Rave,
I will try another solution. I will use the editor. There a user can upload and choose images directly.
Aber ich kann dir empfehlen mal den installer etwas genauer unter die Lupe zu nehmen, da ist ein Abschnitt, der dir genau zeigt,
wie der Upload einer Datei mit dem Joomla-Framework funktioniert. Hier ein Ausschnitt aus der install.php (admin->comp->installer->models):

Code: Select all

function _getPackageFromUpload()
   {
      // Get the uploaded file information
      $userfile = JRequest::getVar('install_package', null, 'files', 'array' );

      // Make sure that file uploads are enabled in php
      if (!(bool) ini_get('file_uploads')) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('WARNINSTALLFILE'));
         return false;
      }

      // Make sure that zlib is loaded so that the package can be unpacked
      if (!extension_loaded('zlib')) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('WARNINSTALLZLIB'));
         return false;
      }

      // If there is no uploaded file, we have a problem...
      if (!is_array($userfile) || $userfile['size'] < 1) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('No file selected'));
         return false;
      }

      // Check if there was a problem uploading the file.
      if ( $userfile['error'] )
      {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('WARNINSTALLUPLOADERROR'));
         return false;
      }

      // Build the appropriate paths
      $config =& JFactory::getConfig();
      $tmp_dest    = $config->getValue('config.tmp_path').DS.$userfile['name'];
      $tmp_src   = $userfile['tmp_name'];

      // Move uploaded file
      jimport('joomla.filesystem.file');
      $uploaded = JFile::upload($tmp_src, $tmp_dest);

      // Unpack the downloaded package file
      $package = JInstallerHelper::unpack($tmp_dest);

      return $package;
   }

You don't need zlib or unpack. Change the $tmp_dest to the final destination where the file should be (including the filename) and you're done.  ;)
Greetz Aljoscha

fattykid17
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Sun Oct 23, 2005 6:49 pm

Re: Image storing for a component

Postby fattykid17 » Wed Aug 08, 2007 8:50 am

Any luck with the component? It sounds like a useful component. I wanted to develop the same sort of thing. Kind of like endurancelog component, except with more options for exercises instead of just sports. And the ability to track progress / improvement. How far along are you on the component ?

NeoAnderson1982
Joomla! Intern
Joomla! Intern
Posts: 77
Joined: Wed Aug 01, 2007 3:32 pm

Re: Image storing for a component

Postby NeoAnderson1982 » Wed Aug 08, 2007 3:48 pm

I've seen that Galileo Computing will bring up a book in september about developping in Joomla! I will wait for it, because I can't get a clue how to store the content of an editor of a form in the database...
The tutz don't give a hint to it (in my opinion) and the article-comp has not got a good comment to see through the techniques...
Maybe you can give me the clue???


Return to “Joomla! 1.5 Coding”

Who is online

Users browsing this forum: No registered users and 8 guests