Здравствуйте.
Использую OCStore1.5.5 + модуль для форм Ajax Contact Form 0.5
Хочу добавить в нее фал для загрузки
Для этого в контроллере добавила
public function upload() {
$this->language->load('product/product');
$json = array();
if (!empty($this->request->files['file']['name'])) {
$filename = basename(preg_replace('/[^a-zA-Z0-9\.\-\s+]/', '', html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')));
if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 64)) {
$json['error'] = $this->language->get('error_filename');
}
// Allowed file extension types
$allowed = array();
$filetypes = explode("\n", $this->config->get('config_file_extension_allowed'));
foreach ($filetypes as $filetype) {
$allowed[] = trim($filetype);
}
if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
$json['error'] = $this->language->get('error_filetype');
}
// Allowed file mime types
$allowed = array();
$filetypes = explode("\n", $this->config->get('config_file_mime_allowed'));
foreach ($filetypes as $filetype) {
$allowed[] = trim($filetype);
}
if (!in_array($this->request->files['file']['type'], $allowed)) {
$json['error'] = $this->language->get('error_filetype');
}
// Check to see if any PHP files are trying to be uploaded
$content = file_get_contents($this->request->files['file']['tmp_name']);
if (preg_match('/\<\?php/i', $content)) {
$json['error'] = $this->language->get('error_filetype');
}
if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
$json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
}
} else {
$json['error'] = $this->language->get('error_upload');
}
if (!$json && is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
$json['file'] = $filename;
move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $filename);
$json['success'] = $this->language->get('text_upload');
}
$this->response->setOutput(json_encode($json));
}
Присоединила файл к письму
if(isset($this->request->post['file'])){
$mail->addAttachment(DIR_DOWNLOAD.$this->request->post['file']);
}
$mail->send();
в тпл файле добавила вывод и скрипт
<div>
<b>File</b><br />
<input type="button" name="btn_file" id="btn_file" value="Select file" />
<input type="hidden" name="file" id="file" value="test.bmp" />
<label id="lbl_file"></label>
<br /><br />
<b><?php echo $entry_enquiry; ?></b><br />
</div>
<script type="text/javascript" src="catalog/view/javascript/jquery/ajaxupload.js"></script>
<script type="text/javascript"><!--
new AjaxUpload('#btn_file', {
action: '<?php echo $action; ?>',
name: 'file',
autoSubmit: true,
responseType: 'json',
onSubmit: function(file, extension) {
$('#btn_file').after('<img src="catalog/view/theme/default/image/loading.gif" class="loading" style="padding-left: 5px;" />');
//$('#btn_file').attr('disabled', true);
},
onComplete: function(file, json) {
//$('#btn_file').attr('disabled', false);
$('.error').remove();
if (json['success']) {
$('#lbl_file').html(json['file']);
$('#file').val(json['file']);
}
if (json['error']) {
$('#btn_file').after('<span class="error">' + json['error'] + '</span>');
}
$('.loading').remove();
}
});
//--></script>
После прикрепления файла просто крутится loading.gif Файл к письму не прикрепляется(
прошу помощи