Jump to content

How To upload files in own module


kavillock

Recommended Posts

i want upload files to presta 1.6, i wrote module, but i didnt know how to upload files and get in in other hook
please help
 

	public function getContent(){
		$output = null;

//		if (Tools::isSubmit('submit'.$this->name))
//		{
//			$page = strval(Tools::getValue('NLCimage'));
//			if (!$page)
//				$output .= $this->displayError($this->l('Invalid Image'));
//			else
//			{
//				Configuration::updateValue('NLCimage', $page);
//				$output .= $this->displayConfirmation($this->l('Settings updated'));
//			}
//		}
		return $output.$this->displayForm();
	}
	
	public function displayForm(){
		// Get default language
		$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');

		// Init Fields form array
		$fields_form[0]['form'] = array(
			'legend' => array(
				'title' => $this->l('Settings'),
			),
			'input' => array(
				array(
					'type' => 'file',
					'name' => 'NLCimage',
					'multiple' => true,
					'label' => $this->l('Wybierz obrazki'),
					'desc' => $this->l('Przytrzymaj crtl aby wybrać kilka plików.'),
					'required' =>   true,
					'lang'  =>  false,
					'display_image' => true,
				)
			),
			'submit' => array(
				'title' => $this->l('Save'),
				'class' => 'button'
			)
		);

		$helper = new HelperForm();

		// Module, token and currentIndex
		$helper->module = $this;
		$helper->name_controller = $this->name;
		$helper->token = Tools::getAdminTokenLite('AdminModules');
		$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

		// Language
		$helper->default_form_language = $default_lang;
		$helper->allow_employee_form_lang = $default_lang;

		// Title and toolbar
		$helper->title = $this->displayName;
		$helper->show_toolbar = true;		// false -> remove toolbar
		$helper->toolbar_scroll = true;		// yes - > Toolbar is always visible on the top of the screen.
		$helper->submit_action = 'submit'.$this->name;
		$helper->toolbar_btn = array(
			'save' =>
			array(
				'desc' => $this->l('Save'),
				'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
				'&token='.Tools::getAdminTokenLite('AdminModules'),
			),
			'back' => array(
				'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
				'desc' => $this->l('Back to list')
			)
		);

		// Load current value
		$helper->fields_value['NLCimage'] = Configuration::get('NLCimage');

		return $helper->generateForm($fields_form);
	}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...