[SOLVED]Turn Off Joomla! Warning

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
User avatar
knucklesmcfly
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Thu Jan 15, 2009 4:28 am

[SOLVED]Turn Off Joomla! Warning

Post by knucklesmcfly » Fri Feb 26, 2010 4:22 pm

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... :pop
Last edited by knucklesmcfly on Tue Mar 02, 2010 1:59 pm, edited 1 time in total.

Marcus Stafford
Joomla! Explorer
Joomla! Explorer
Posts: 308
Joined: Tue Apr 17, 2007 8:50 am
Location: Norwich, England
Contact:

Re: Turn Off Joomla! Warning

Post by Marcus Stafford » Fri Feb 26, 2010 4:27 pm

Go to Global Configuration and click Server.

Set 'Error Reporting' to None.
Joomla! Managed Hosting, Web Design, Hack Repairs and Consulting ~ https://www.wintercorn.com

User avatar
knucklesmcfly
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Thu Jan 15, 2009 4:28 am

Re: Turn Off Joomla! Warning

Post by knucklesmcfly » Fri Feb 26, 2010 5:08 pm

Tried that. It didn't work.

User avatar
dhuelsmann
Joomla! Master
Joomla! Master
Posts: 19659
Joined: Sun Oct 02, 2005 12:50 am
Location: Omaha, NE
Contact:

Re: Turn Off Joomla! Warning

Post by dhuelsmann » Fri Feb 26, 2010 6:13 pm

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

User avatar
knucklesmcfly
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Thu Jan 15, 2009 4:28 am

Re: Turn Off Joomla! Warning

Post by knucklesmcfly » Fri Feb 26, 2010 7:32 pm

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';
				}   
			
		}

User avatar
dhuelsmann
Joomla! Master
Joomla! Master
Posts: 19659
Joined: Sun Oct 02, 2005 12:50 am
Location: Omaha, NE
Contact:

Re: Turn Off Joomla! Warning

Post by dhuelsmann » Fri Feb 26, 2010 7:35 pm

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

User avatar
knucklesmcfly
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Thu Jan 15, 2009 4:28 am

Re: Turn Off Joomla! Warning

Post by knucklesmcfly » Sat Feb 27, 2010 10:58 am

dhuelsmann wrote:Where are you making sure that $image is set to null before input?
In the controller:

Code: Select all

$image = JRequest::getVar('image', null, 'files');

User avatar
knucklesmcfly
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Thu Jan 15, 2009 4:28 am

Re: Turn Off Joomla! Warning

Post by knucklesmcfly » Sat Feb 27, 2010 11:15 am

When I echo out $image it gives me the value of Array.

User avatar
jlighthouse
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Sun Feb 14, 2010 2:07 pm

Re: Turn Off Joomla! Warning

Post by jlighthouse » Sat Feb 27, 2010 3:39 pm

Hi, I had the same error, just put this code into my conrtoller:

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)) {
                ...
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:

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;
	}
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
Currently developing one of the few and free Joomla ticket system, called Lighthouse - http://extensions.joomla.org/extensions ... -desk/8098

User avatar
knucklesmcfly
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Thu Jan 15, 2009 4:28 am

Re: Turn Off Joomla! Warning

Post by knucklesmcfly » Mon Mar 01, 2010 3:16 pm

This seems like an uncanny way to accomplish this. But I'm going to give it a try.

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: Turn Off Joomla! Warning

Post by dam-man » Tue Mar 02, 2010 9:56 am

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..

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

User avatar
knucklesmcfly
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 198
Joined: Thu Jan 15, 2009 4:28 am

Re: Turn Off Joomla! Warning

Post by knucklesmcfly » Tue Mar 02, 2010 1:59 pm

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.

User avatar
dam-man
Joomla! Exemplar
Joomla! Exemplar
Posts: 7961
Joined: Fri Sep 09, 2005 2:13 pm
Location: The Netherlands
Contact:

Re: Turn Off Joomla! Warning

Post by dam-man » Wed Mar 03, 2010 8:18 am

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.
You're welcome. And have fun with your script!
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards


Locked

Return to “Joomla! 1.5 Coding”