Jump to content

PrestaShop - upload files


Recommended Posts

have a problem with downloading files. var_dump($_FILES["filename"]); is null. But var_dump($_POST["filename"]); is string(31) "latina-ceramica_irina_83170.jpg". And I need to copy this file to directory modules/"my module"/img/ and insert into db $_POST['alt'] and name of file. This is module for Prestashop. My php verion is 5.3.5

This is my form:

<form action="" method="post" enctype="multipart/form-data">
	<fieldset>
	<legend>'.$this->l('Загрузка новой картинки').'</legend>
	'.$this->l('link').':<br />
	<input type="text" name="alt" value="" /><br />
	'.$this->l('Выберите изображение').':<br />
	<input type="file" name="filename" /><br />
	<br />
	<input type="submit" name="btnSubmit" class="button" value="'.$this->l('Загрузить').'">
</fieldset>
</form>

 

And this is function

private function _postProcess() {
var_dump($_FILES["filename"]);
if($_FILES["filename"]["size"] > 1024*3*1024)
{
	echo ("Размер файла превышает три мегабайта");
	exit;
}
// Проверяем загружен ли файл
if(is_uploaded_file($_FILES["filename"]["tmp_name"]))
{
	// Если файл загружен успешно, перемещаем его
	// из временной директории в конечную
	move_uploaded_file($_FILES["filename"]["tmp_name"], "/path/to/file/".$_FILES["filename"]["name"]);
	Db::getInstance()->Execute("INSERT INTO `"._DB_PREFIX_."pay_icon`
						(icon_img, icon_link) VALUES ( '232', '234234')");
} else {
	echo("Ошибка загрузки файла");
}
}

Edited by hottern (see edit history)
Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...
Hello,

I am developing a module that among other functions I want to send me an email to the client that I selected and with the files they attach.

When I upload files through code:

$ Fields_form = array (

'Form' => array (

'Legend' => array (

'Title' => $ this-> l ('Email Receipt Form'). '=> Client Name:'. $ Name_customer. ' - Email: '. $ Email_customer.' - Client language: '. $ Name_lang,

'Icon' => 'icon-cogs'

),

'Input' => array (

Array (

'Type' => 'text',

'Label' => $ this-> l ('Email Client'),

'Name' => 'email',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

),

Array (

'Type' => 'text',

'Label' => $ this-> l ('E-mail copy'),

'Name' => 'ACCOUNT_EMAIL',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ this-> l ('Check if this is the email you want to send a copy of the email sent.')

),

Array (

'Type' => 'file',

'Label' => $ this-> l ('Attach documents'),

'Name' => 'FILE',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ test,

(to be continued)

 

 It works flawlessly, but only sends one attachment at a time.

I wanted to now send more than one attachment through what I did in the following code:

$ Fields_form = array (

'Form' => array (

'Legend' => array (

'Title' => $ this-> l ('Email Receipt Form'). '=> Client Name:'. $ Name_customer. ' - Email: '. $ Email_customer.' - Client language: '. $ Name_lang,

'Icon' => 'icon-cogs'

),

'Input' => array (

Array (

'Type' => 'text',

'Label' => $ this-> l ('Email Client'),

'Name' => 'email',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

),

Array (

'Type' => 'text',

'Label' => $ this-> l ('E-mail copy'),

'Name' => 'ACCOUNT_EMAIL',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ this-> l ('Check if this is the email you want to send a copy of the email sent.')

),

Array (

'Type' => 'file',

'Label' => $ this-> l ('Attach documents'),

'Name' => 'FILE',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ test,

'Ajax' => true,

'Multiple' => true,

),

(to be continued)

This code uploads multiple files but I can not get it to work.

I can not get the second image code to work.

Someone can help me"?

Thank you

Link to comment
Share on other sites

  • 2 months later...

Hello,

I am developing a module that among other functions I want to send me an email to the client that I selected and with the files they attach.

When I upload files through code:

$ Fields_form = array (

'Form' => array (

'Legend' => array (

'Title' => $ this-> l ('Email Receipt Form'). '=> Client Name:'. $ Name_customer. ' - Email: '. $ Email_customer.' - Client language: '. $ Name_lang,

'Icon' => 'icon-cogs'

),

'Input' => array (

Array (

'Type' => 'text',

'Label' => $ this-> l ('Email Client'),

'Name' => 'email',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

),

Array (

'Type' => 'text',

'Label' => $ this-> l ('E-mail copy'),

'Name' => 'ACCOUNT_EMAIL',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ this-> l ('Check if this is the email you want to send a copy of the email sent.')

),

Array (

'Type' => 'file',

'Label' => $ this-> l ('Attach documents'),

'Name' => 'FILE',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ test,

(to be continued)

 

 It works flawlessly, but only sends one attachment at a time.

I wanted to now send more than one attachment through what I did in the following code:

$ Fields_form = array (

'Form' => array (

'Legend' => array (

'Title' => $ this-> l ('Email Receipt Form'). '=> Client Name:'. $ Name_customer. ' - Email: '. $ Email_customer.' - Client language: '. $ Name_lang,

'Icon' => 'icon-cogs'

),

'Input' => array (

Array (

'Type' => 'text',

'Label' => $ this-> l ('Email Client'),

'Name' => 'email',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

),

Array (

'Type' => 'text',

'Label' => $ this-> l ('E-mail copy'),

'Name' => 'ACCOUNT_EMAIL',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ this-> l ('Check if this is the email you want to send a copy of the email sent.')

),

Array (

'Type' => 'file',

'Label' => $ this-> l ('Attach documents'),

'Name' => 'FILE',

'Search' => false,

'Orderby' => false,

'Align' => 'center',

'Desc' => $ test,

'Ajax' => true,

'Multiple' => true,

),

(to be continued)

This code uploads multiple files but I can not get it to work.

I can not get the second image code to work.

Someone can help me"?

Thank you

The ContactController.php does something very similar, you should have a look into that postProcess() function. Turns out that in Mail::send() the $file_attachment is used to send the attachment with it. So basically, most things are handled by Mail::send!

Link to comment
Share on other sites

×
×
  • Create New...