File upload in custom component

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
biometrx
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Sat Dec 11, 2010 11:23 pm
Location: london
Contact:

File upload in custom component

Post by biometrx » Mon Jun 13, 2011 9:11 am

I have been stuck on a component i'm building for quite sometime now. On clicking on the new button a page is displayed in view whose function is to collect info such as name, publish or unpublish, client and so on and so forth. The problem is, i need a field for uploading images.

My question is, i have a save function, function store(), in the model which uses the table to save items from the form into the database table by doing the table bind, check_in, save e.t.c.

So, i have created the form fields for all items i need in the tmpl folder of my view but what i really need is for all the items in the form field to be saved to the table however, i need only the url path to the image and image name to be saved to the database with the image itself saved to the file folder system of joomla. I presume i'll do that with the help of JFolders.

I'v searched google but havent quite found what i'm looking for. Could someone with experience with this shed some light on how i could do this?

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30890
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: File upload in custom component

Post by Per Yngve Berg » Mon Jun 13, 2011 10:30 am

This is from the Annonces extension:

Code: Select all

function enregistrerPhoto( $file, $photoId, $pMaxUploadKoSize, $comp )
	{
		global $mainframe;
		$result = true;
		if ( !empty($file['name']) )  
		{
			jimport('joomla.filesystem.file');
			
			//check the image
			$check = $this->check($file, (int) $pMaxUploadKoSize);
			
			if ($check == false) {
				return false;
			}
			
			//sanitize the image filename
			$filename = $photoId.'.jpg';
			$filepath = $this->photoPathTemp . DS . $filename;

			if ( JFile::upload($file['tmp_name'], $filepath)) 
			{
				// On redimensionne la photo
				$result = $this->dimensionnerPhotos( $filename ); 
			}
			/**else {
				JError::raiseError( 500, JText::_( 'UPLOAD FAILED' ) );
				return false;
			}*/
		}
		return $result;
	}

biometrx
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Sat Dec 11, 2010 11:23 pm
Location: london
Contact:

Re: File upload in custom component

Post by biometrx » Mon Jun 13, 2011 10:39 am

Hello again, thanks for your update. The question is i have been seeing this code but dont even know how to implement it. I already have a store function that saves data from the text input boxes using jtable. Now i've added a an input file upload input box. How do i use that function with the rest of the other text data saved to the db.

Thank you

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30890
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: File upload in custom component

Post by Per Yngve Berg » Mon Jun 13, 2011 10:57 am

Get the extension and study the source files.

http://extensions.joomla.org/extensions ... -ads/11937

biometrx
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Sat Dec 11, 2010 11:23 pm
Location: london
Contact:

Re: File upload in custom component

Post by biometrx » Mon Jun 13, 2011 11:07 am

Thank you


Locked

Return to “Joomla! 1.5 Coding”