[SOLVED]Turn Off Joomla! Warning
- knucklesmcfly
- Joomla! Enthusiast
- Posts: 198
- Joined: Thu Jan 15, 2009 4:28 am
[SOLVED]Turn Off Joomla! Warning
Hey all...I have a script in MVC form that handles a form post with an optional file upload...My problem is that when the user does not input a file to upload, it's optional, I get a Joomla! warning on the redirected page that says, "Warning: Failed to move file." I know it's a Joomla! warning because it has the warning icon.
How do I turn that off?
Thanks all...
How do I turn that off?
Thanks all...
Last edited by knucklesmcfly on Tue Mar 02, 2010 1:59 pm, edited 1 time in total.
-
- Joomla! Explorer
- Posts: 308
- Joined: Tue Apr 17, 2007 8:50 am
- Location: Norwich, England
- Contact:
Re: Turn Off Joomla! Warning
Go to Global Configuration and click Server.
Set 'Error Reporting' to None.
Set 'Error Reporting' to None.
Joomla! Managed Hosting, Web Design, Hack Repairs and Consulting ~ https://www.wintercorn.com
- knucklesmcfly
- Joomla! Enthusiast
- Posts: 198
- Joined: Thu Jan 15, 2009 4:28 am
Re: Turn Off Joomla! Warning
Tried that. It didn't work.
- dhuelsmann
- Joomla! Master
- Posts: 19659
- Joined: Sun Oct 02, 2005 12:50 am
- Location: Omaha, NE
- Contact:
Re: Turn Off Joomla! Warning
Why is it trying to upload the file if the user didn't input anything? Sounds like you need to adjust your code so that it doesn't try to upload if there was no input
Regards, Dave
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org
- knucklesmcfly
- Joomla! Enthusiast
- Posts: 198
- Joined: Thu Jan 15, 2009 4:28 am
Re: Turn Off Joomla! Warning
Here's the code:
Code: Select all
if ($image)
{
jimport('joomla.filesystem.file');
$imagename = JFile::makeSafe($image['name']);
$src = $image['tmp_name'];
$dest = JPATH_COMPONENT . DS . "uploads" . DS . $imagename;
if ( strtolower(JFile::getExt($imagename) ) == 'jpg' || 'png')
{
if ( JFile::upload($src, $dest) ) {
$filemsg = 'Your image has been uploaded';
} else {
$filemsg = 'There was an error uploading your image';
}
} else {
$filemsg = 'Image is not proper file extension';
}
}
- dhuelsmann
- Joomla! Master
- Posts: 19659
- Joined: Sun Oct 02, 2005 12:50 am
- Location: Omaha, NE
- Contact:
Re: Turn Off Joomla! Warning
Where are you making sure that $image is set to null before input?
Regards, Dave
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org
- knucklesmcfly
- Joomla! Enthusiast
- Posts: 198
- Joined: Thu Jan 15, 2009 4:28 am
Re: Turn Off Joomla! Warning
In the controller:dhuelsmann wrote:Where are you making sure that $image is set to null before input?
Code: Select all
$image = JRequest::getVar('image', null, 'files');
- knucklesmcfly
- Joomla! Enthusiast
- Posts: 198
- Joined: Thu Jan 15, 2009 4:28 am
Re: Turn Off Joomla! Warning
When I echo out $image it gives me the value of Array.
- jlighthouse
- Joomla! Intern
- Posts: 78
- Joined: Sun Feb 14, 2010 2:07 pm
Re: Turn Off Joomla! Warning
Hi, I had the same error, just put this code into my conrtoller:
The idea is to clear the garbage in the $files (a bunch of unsets) even if nothing was uploaded. And then in the model I upload files:
When I not only upload files, but also keep tracks in the DB, what is not recommended.
This code checked with several extensions. Pay attention to the unset instructions. I think it is your solution
jlighthouse
Code: Select all
//-----------------------------> ATTACHMENTS FILE SIZE CHECKS <-----------------------------\\
// import joomla clases to manage file system
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
// get posted attachments
$files = JRequest::getVar('attachments', 'post', 'files', 'array');
// get application reference
$app =& JFactory::getApplication();
// get Lighthouse config
$config =& LighthouseModelConfig::getInstance();
// process attachments
$filesCount = count($files['name']);
for ($i = 0; $i < $filesCount; $i++) {
// check posted attachments
if (strlen(trim($files['name'][$i])) > 0) {
// get maximum size of attachment in bytes
$maxSize = (int)$config->getAttachmentSettings('maximumSize');
// check attachment size
if ($maxSize > 0 && (int)$files['size'][$i] > $maxSize) {
// set error notice
$app->setUserState('warningMsg', JText::_('ATTACHMENT_HUGE').' ( '.JFile::getName($files['name'][$i]).' ) ');
if ($catid != 0)
$this->setRedirect(JRoute::_('index.php?option=com_lighthouse&controller=question&task=create&catid='. $catid .'&'. JUtility::getToken() .'=1', false));
else
$this->setRedirect(JRoute::_('index.php?option=com_lighthouse&controller=question&task=create&zonid='. $zonid .'&'. JUtility::getToken() .'=1', false));
return;
}
}
else {
unset($files['name'][$i]);
unset($files['type'][$i]);
unset($files['tmp_name'][$i]);
unset($files['error'][$i]);
unset($files['size'][$i]);
}
}
$app->setUserState('warningMsg', '');
//-----------------------------> ATTACHMENTS FILE SIZE CHECKS <-----------------------------\\
// get Ticket model
$modelTicket =& $this->getModel('Ticket');
$post = JRequest::get('post');
// let the model save all necessary data
if ($msgid = $modelTicket->store($post, $files)) {
...
Code: Select all
function store($post, $files)
{
// get Ticket table
$tableTicket =& $this->getTable();
// prepare grouping
$group = $this->_db->nameQuote('catid') .' = '. intval($post['catid']);
// store ticket
if (!$this->save($post, true, $tableTicket, $group))
return false;
// get Message table
$tableMessage =& $this->getTable('Message');
// specify some post values
$now = JFactory::getDate();
$post['create_date'] = $now->toMySQL();
$post['tickid'] = $tableTicket->tickid;
// prepare grouping
$group = $this->_db->nameQuote('tickid') .' = '. intval($tableTicket->tickid);
// store message
if (!$this->save($post, true, $tableMessage, $group))
return false;
// get Lighthouse config
$config =& LighthouseModelConfig::getInstance();
// process files
if ($config->getAttachmentSettings('isUploadsActivated')) {
for ($i = 0; $i < $config->getAttachmentSettings('allowedNumberPossibleFileUploads'); $i++) {
if (!empty($files['name'][$i])) {
// then create assigned attachment
$attachment = new StdClass;
$attachment->attid = 0;
$attachment->name = JFile::makeSafe(JFile::stripExt($files['name'][$i]));
$attachment->extension = JFile::getExt($files['name'][$i]);
// create folder for attachment
if (!JFolder::create(JPATH_COMPONENT_SITE.DS.'attachments'.DS.'message '.$tableMessage->msgid, 0775)) {
// handle failed folder creation
$this->setError(get_class($this).'::store attachment failed - cannot create folder');
return false;
}
else
$attachment->folder = JPATH_COMPONENT_SITE.DS.'attachments'.DS.'message '.$tableMessage->msgid;
$attachment->sizekb = $files['size'][$i] / 1024;
$attachment->msgid = $tableMessage->msgid;
// and store it
if(!$this->_db->insertObject('#__lighthouse_attachment', $attachment, 'attid')) {
$this->setError(get_class( $this ).'::store attachment failed - '.$this->_db->getErrorMsg());
return false;
}
// specify destination folder
$filePath = JPath::clean($attachment->folder.DS.$attachment->name.'.'.$attachment->extension);
// save file in the folder
if (!JFile::upload($files['tmp_name'][$i], $filePath)) {
// handle failed upload
$this->setError(get_class( $this ).'::save attachment failed - cannot upload file');
return false;
}
}
}
}
return $tableMessage->msgid;
}
This code checked with several extensions. Pay attention to the unset instructions. I think it is your solution
jlighthouse
Currently developing one of the few and free Joomla ticket system, called Lighthouse - http://extensions.joomla.org/extensions ... -desk/8098
- knucklesmcfly
- Joomla! Enthusiast
- Posts: 198
- Joined: Thu Jan 15, 2009 4:28 am
Re: Turn Off Joomla! Warning
This seems like an uncanny way to accomplish this. But I'm going to give it a try.
- dam-man
- Joomla! Exemplar
- Posts: 7961
- Joined: Fri Sep 09, 2005 2:13 pm
- Location: The Netherlands
- Contact:
Re: Turn Off Joomla! Warning
Do you one or more attachments at one save?
You could simply check if the temp name is filled, if so process upload else don't upload. Looks much easier to me..
You could simply check if the temp name is filled, if so process upload else don't upload. Looks much easier to me..
Code: Select all
if ($image['tmp_name'] != '')
{
jimport('joomla.filesystem.file');
$imagename = JFile::makeSafe($image['name']);
$src = $image['tmp_name'];
$dest = JPATH_COMPONENT . DS . "uploads" . DS . $imagename;
if ( strtolower(JFile::getExt($imagename) ) == 'jpg' || 'png')
{
if ( JFile::upload($src, $dest) ) {
$filemsg = 'Your image has been uploaded';
} else {
$filemsg = 'There was an error uploading your image';
}
} else {
$filemsg = 'Image is not proper file extension';
}
}
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards
Dutch Boards | Joomla Coding Boards | English Support Boards
- knucklesmcfly
- Joomla! Enthusiast
- Posts: 198
- Joined: Thu Jan 15, 2009 4:28 am
Re: Turn Off Joomla! Warning
dam-man you know what? It's funny because this was actually the solution I wound up using. I use a check to see if $file['name'] is not null.
Thanks much for the reply.
Thanks much for the reply.
- dam-man
- Joomla! Exemplar
- Posts: 7961
- Joined: Fri Sep 09, 2005 2:13 pm
- Location: The Netherlands
- Contact:
Re: Turn Off Joomla! Warning
You're welcome. And have fun with your script!knucklesmcfly wrote:dam-man you know what? It's funny because this was actually the solution I wound up using. I use a check to see if $file['name'] is not null.
Thanks much for the reply.
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards
Dutch Boards | Joomla Coding Boards | English Support Boards