質問編集履歴
2
モデルのコードとテンプレートのコードの追加、
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
### 質問内容
|
|
2
2
|
phpでモデルクラスを作成して、書き換えていたのですが、画像が表示されなくなり困っています。
|
|
3
3
|
画像以外はうまく表示されました。
|
|
4
|
+
モデルに書き換えたことで、画像ファイルに画像が入らなくなったのが原因みたいです。
|
|
4
5
|
考えられる理由は何でしょうか?ご回答お願いいたします。
|
|
5
6
|
|
|
6
7
|
### 変更前
|
1
modelクラスと実際に表示している画面のコードを載せました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -57,4 +57,100 @@
|
|
|
57
57
|
$luck = new Luck();
|
|
58
58
|
$luck_image = $luck->updateImage($fname);
|
|
59
59
|
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
質問追記
|
|
65
|
+
model/lucks.php
|
|
66
|
+
```
|
|
67
|
+
<?php
|
|
68
|
+
require_once("../config.php");
|
|
69
|
+
|
|
70
|
+
class Luck {
|
|
71
|
+
private $db;
|
|
72
|
+
function __construct() {
|
|
73
|
+
$user = root;
|
|
74
|
+
$password = root;
|
|
75
|
+
$dbname = 'luck';
|
|
76
|
+
$host = 'localhost';
|
|
77
|
+
$dsn = "mysql:host={$host};dbname={$dbname};charset=utf8";
|
|
78
|
+
$this->db = new PDO($dsn, $user, $password);
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public function addContent($name){
|
|
83
|
+
$sql = "INSERT INTO lucks (content) VALUES ('" . $name . "')";
|
|
84
|
+
error_log("sql=" . $sql);
|
|
85
|
+
$stm = $this->db->prepare($sql);
|
|
86
|
+
$stm->execute();
|
|
87
|
+
|
|
88
|
+
return $this->db->lastInsertId();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public function updateImage($fname){
|
|
92
|
+
$sql = "UPDATE lucks set attach_filename = '" . $fname . "' WHERE id = ".$id;
|
|
93
|
+
error_log("sql=" . $sql);
|
|
94
|
+
$stm = $this->db->prepare($sql);
|
|
95
|
+
$stm->execute();
|
|
96
|
+
return $this->db->lastInsertId();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public function getLuckByAll($id,$content,$attach_filename,$deleted_at){
|
|
100
|
+
$sql = "SELECT * FROM lucks";
|
|
101
|
+
error_log("sql=" . $sql);
|
|
102
|
+
$stm = $this->db->prepare($sql);
|
|
103
|
+
$stm->execute();
|
|
104
|
+
$record_list = $stm->fetchAll();
|
|
105
|
+
return $record_list;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
画像を表示しているページ
|
|
113
|
+
(index.tpl)
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
<!DOCTYPE html>
|
|
117
|
+
<html>
|
|
118
|
+
<head>
|
|
119
|
+
<title>a</title>
|
|
120
|
+
<meta charset="utf-8">
|
|
121
|
+
</head>
|
|
122
|
+
<body>
|
|
123
|
+
<table border='1'>
|
|
124
|
+
<tr>
|
|
125
|
+
<td>内容</td>
|
|
126
|
+
<tr>
|
|
127
|
+
{foreach from=$indexdata item=current}
|
|
128
|
+
<td>{$current.id}</td>
|
|
129
|
+
<td>{$current.content}</td>
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
{if $current.attach_filename}
|
|
133
|
+
|
|
134
|
+
<td><img src='/luckfile/images/{$current.attach_filename}'/></td>
|
|
135
|
+
|
|
136
|
+
{else}
|
|
137
|
+
<td>no image</td>
|
|
138
|
+
{/if}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
<td><form method="POST" action="delete.php">
|
|
142
|
+
<input type="hidden" name="id" value='{$current.id}'>
|
|
143
|
+
<input type="submit" value="削除"></form></td>
|
|
144
|
+
<td>
|
|
145
|
+
<a href="/luckfile/edit_menu.php?id={$current.id}">編集</a>
|
|
146
|
+
</td>
|
|
147
|
+
<td>
|
|
148
|
+
<a href="/luckfile/show.php?id={$current.id}">詳細</a>
|
|
149
|
+
</td>
|
|
150
|
+
</tr>
|
|
151
|
+
{/foreach}
|
|
152
|
+
</table>
|
|
153
|
+
</body>
|
|
154
|
+
</html>
|
|
155
|
+
|
|
60
156
|
```
|