我是Opencart的新手,它真的很棒。Opencart代碼文件上傳
我只想在數據庫中插入圖片,但我無法上傳。這是我所做的。
模板:
<div class="col-sm-10">
<img src="" name="image" id="image" style="width: 26%;height: 100px;" >
<input type="file"
name="photo"
value="<?php echo $photo; ?>"
placeholder="<?php echo $entry_photo; ?>"
id="photo"
onChange="PreviewImages();"/>
<?php if ($error_photo) { ?>
<div class="text-danger"><?php echo $error_photo; ?></div>
<?php } ?>
</div>
控制器:
if (is_uploaded_file($this->request->files['photo']['tmp_name'])) {
$handle = fopen($this->request->files['photo']['tmp_name'], "r");
// If we know there is only a 10 chars PIN per line
// it is better to lower the expected line length
// to lower the memory consumption...
while (($pins = fgetcsv($handle, 50, ",")) !== false) {
$data['photo'][] = $pins; // there is only one PIN per line
}
fclose($handle);
} else {
$data['photo'] = array();
}
型號:
$this->db->query("
INSERT INTO " . DB_PREFIX . "customer
SET customer_group_id = '" . (int)$customer_group_id . "',
store_id = '" . (int)$this->config->get('config_store_id') . "',
firstname = '" . $this->db->escape($data['firstname']) . "',
lastname = '" . $this->db->escape($data['lastname']) . "',
photo = '" . $this->db->escape($data['photo']) . "',
date = '" . $this->db->escape($data['date']) . "',
email = '" . $this->db->escape($data['email']) . "',
telephone = '" . $this->db->escape($data['telephone']) . "',
fax = '" . $this->db->escape($data['fax']) . "',
custom_field = '" . $this->db->escape(isset($data['custom_field']['account']) ? serialize($data['custom_field']['account']) : '') . "',
salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "',
password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "',
newsletter = '" . (isset($data['newsletter']) ? (int)$data['newsletter'] : 0) . "',
ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "',
status = '1',
approved = '" . (int)!$customer_group_info['approval'] . "',
date_added = NOW()
");
$customer_id = $this->db->getLastId();
「*,但我無法上傳*「:請說明發生了什麼事,可以提供有用的答案。參見[問]的指導方針。 – mins 2015-03-31 05:32:54
儘快幫我解決?那裏有很多付費服務,他們肯定會爲少量的錢做好準備。 – alexandresaiz 2015-03-31 06:23:35
感謝您的回覆。我只是想在註冊時將圖像添加到數據庫中。 – Sruthi 2015-04-02 06:25:14