What API calls to add upload option?
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
What API calls to add upload option?
Can anyone point me in the right direction concerning the following:
I would like to add an upload option to my component in the backend to upload a picture. I would like to do it in a good 1.5 way.
Does anyone have a piece of example code with the right API calls, so I can study it and take the code as a base?
I would like to add an upload option to my component in the backend to upload a picture. I would like to do it in a good 1.5 way.
Does anyone have a piece of example code with the right API calls, so I can study it and take the code as a base?
Last edited by Skruu on Tue Sep 25, 2007 5:33 pm, edited 1 time in total.
Re: What API calls to add upload option?
I would take a look at the media manager in the backend.
Ian
Ian
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!
Re: What API calls to add upload option?
Hi,
I made this to upload txt file for my component. this is the function i wrote, free inspirate by './administrator/components/com_installer/models/install.php'. I think it work for other type of file (png, jpg, ...).
To manipulate File and folder, you need to import JFile and JFolder class.
I use JRequest::getVar with the attribute 'files'.
And the form
enctype="multipart/form-data" method="post"
action="">
I hope this will help you.
Na retrouvé.
I made this to upload txt file for my component. this is the function i wrote, free inspirate by './administrator/components/com_installer/models/install.php'. I think it work for other type of file (png, jpg, ...).
To manipulate File and folder, you need to import JFile and JFolder class.
I use JRequest::getVar with the attribute 'files'.
Code: Select all
public function upload( )
{
jimport('joomla.filesystem.*');
// Récupération du fichier
$userfile = JRequest::getVar('fileEsp', null, 'files', 'array' );
// Check if there was a problem uploading the file.
if ( $userfile['error'] || $userfile['size'] < 1 )
{
JError::raiseWarning('SOME_ERROR_CODE', 'Erreur de transfert du fichier' );
return false;
}
// Build the appropriate paths
$tmp_dest = PATH_TXTUPL.DS.'especes.txt';
$tmp_src = $userfile['tmp_name'];
// Write the file $tmp_src in $tmp_dest folder
if ( JFile::upload($tmp_src, $tmp_dest ) )
{
return true;
}
else
{
return false;
}
}
And the form
enctype="multipart/form-data" method="post"
action="">
I hope this will help you.
Na retrouvé.
Last edited by zian974 on Tue Oct 02, 2007 11:32 am, edited 1 time in total.
-
- Joomla! Apprentice
- Posts: 16
- Joined: Wed Aug 22, 2007 8:41 am
- Location: Germany
- Contact:
Re: What API calls to add upload option?
Well... I tried your example code but I doesn't work 'cause the task doesn't get called.
I implemented the upload-function in my controller where I edit, add and display all other single entries of my component.
Changing the input string of JRoute to match with my component doesn't work also:
Well... here'ss my editied code from the controller. If the method would get called, I would either get a "noooo" or "yeeeees" message:
but nothing happens
I also registered the task in the constructor of my controller:
I implemented the upload-function in my controller where I edit, add and display all other single entries of my component.
Changing the input string of JRoute to match with my component doesn't work also:
Code: Select all
<form class="formEsp" name="upL_txtEsp" id="upL_txtEsp" enctype="multipart/form-data" method="post"action="<?php echo JRoute::_( 'index.php?option=com_redlight&controller=redlight&task=upload&id='.$this->rl_ad->id ) ?>">
<fieldset>
<legend>Anzeigenfoto hochladen:</legend>
<p>
<label for="fileEsp" title="Wähle ein Foto aus">Foto</label>
<input type="file" name="fileEsp" id="fileEsp" title="Wähle ein Foto aus" size="50"/>
<input type="submit" value="hinzufügen" size="50"/>
</p>
</fieldset>
</form>
Well... here'ss my editied code from the controller. If the method would get called, I would either get a "noooo" or "yeeeees" message:
Code: Select all
function upload()
{
jimport('joomla.filesystem.*');
// Récupération du fichier
$userfile = JRequest::getVar('fileEsp', null, 'files', 'array' );
// Check if there was a problem uploading the file.
if ( $userfile['error'] || $userfile['size'] < 1 )
{
JError::raiseWarning('SOME_ERROR_CODE', 'noooooo' );
return false;
}
else JError::raiseWarning('SOME_ERROR_CODE', 'yeeeees' );
// Build the appropriate paths
$tmp_dest = PATH_TXTUPL.DS.'especes.txt';
$tmp_src = $userfile['tmp_name'];
// Write the file $tmp_src in $tmp_dest folder
if ( JFile::upload($tmp_src, $tmp_dest ) )
{
return true;
}
else
{
return false;
}
}
but nothing happens
I also registered the task in the constructor of my controller:
Code: Select all
function __construct()
{
parent::__construct();
// Register Extra tasks
// wir mappen add zu edit... edit ist ja nix anders wie add nur mit gefüllter form etc..
$this->registerTask( 'add' , 'edit' );
$this->registerTask( 'upload' , 'upload' );
}
o
Re: What API calls to add upload option?
check where you're getting your task from? And check to make sure it is being retrieved properly. You are sending it via get, and it might be looking for it via post.
Ian
Ian
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!
-
- Joomla! Apprentice
- Posts: 16
- Joined: Wed Aug 22, 2007 8:41 am
- Location: Germany
- Contact:
Re: What API calls to add upload option?
Uhh... I'm using POST to send the file.... so.... I have to differ between GET and POST while retrieving a task?... that's the thirst thing I read now considering joomla tasks.... where can I get further information about this topic and the GET and POST differences in joomla tasks !?
Thanx, Alex
Thanx, Alex
o
-
- Joomla! Apprentice
- Posts: 16
- Joined: Wed Aug 22, 2007 8:41 am
- Location: Germany
- Contact:
Re: What API calls to add upload option?
Well... I found the error... I nested two forms ... it works now, thanx for your help !
o