回答編集履歴
2
追記
test
CHANGED
@@ -101,3 +101,81 @@
|
|
101
101
|
|
102
102
|
|
103
103
|
```
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
# imgタグのsrcからデータを抜くsample
|
108
|
+
|
109
|
+
```javascript
|
110
|
+
|
111
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
112
|
+
|
113
|
+
<script>
|
114
|
+
|
115
|
+
$(function(){
|
116
|
+
|
117
|
+
var fname=$('#testImg').attr('src').match(/([^\/]+?)$/)[1];
|
118
|
+
|
119
|
+
var imgdata;
|
120
|
+
|
121
|
+
var xhr = new XMLHttpRequest();
|
122
|
+
|
123
|
+
xhr.open('GET', $('#img1').attr('src'), true);
|
124
|
+
|
125
|
+
xhr.responseType = 'arraybuffer';
|
126
|
+
|
127
|
+
xhr.onload = function(e) {
|
128
|
+
|
129
|
+
imgdata=this.response;
|
130
|
+
|
131
|
+
};
|
132
|
+
|
133
|
+
xhr.send();
|
134
|
+
|
135
|
+
$('[type=button][value=ajax]').on('click',function(){
|
136
|
+
|
137
|
+
var fd = new FormData($('#f1').get(0));
|
138
|
+
|
139
|
+
fd.append("_img",new Blob([imgdata],{"type":"image/jpeg"}),fname);
|
140
|
+
|
141
|
+
/*ごめんなさい、typeの自動取得が調べられてません*/
|
142
|
+
|
143
|
+
$.ajax({
|
144
|
+
|
145
|
+
url:"recv.php",
|
146
|
+
|
147
|
+
data:fd,
|
148
|
+
|
149
|
+
type:"post",
|
150
|
+
|
151
|
+
processData: false,
|
152
|
+
|
153
|
+
contentType: false,
|
154
|
+
|
155
|
+
success:function(data){
|
156
|
+
|
157
|
+
console.log(data);
|
158
|
+
|
159
|
+
},
|
160
|
+
|
161
|
+
});
|
162
|
+
|
163
|
+
});
|
164
|
+
|
165
|
+
});
|
166
|
+
|
167
|
+
</script>
|
168
|
+
|
169
|
+
<form id="f1" enctype="multipart/form-data" method="post" action="y.php">
|
170
|
+
|
171
|
+
<input type="text" name="title" value="xxx"><br>
|
172
|
+
|
173
|
+
<input type="submit" value="go"><br>
|
174
|
+
|
175
|
+
<input type="button" value="ajax"><br>
|
176
|
+
|
177
|
+
</form>
|
178
|
+
|
179
|
+
<img src="http://example.com/hoge/fuga.jpg" id="testImg">
|
180
|
+
|
181
|
+
```
|
1
追記
test
CHANGED
@@ -77,3 +77,27 @@
|
|
77
77
|
?>
|
78
78
|
|
79
79
|
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
# insert処理
|
84
|
+
|
85
|
+
こうしてみてください
|
86
|
+
|
87
|
+
```PHP
|
88
|
+
|
89
|
+
$sql="insert into imgdata(title,img)values(:t,:i)";
|
90
|
+
|
91
|
+
$stmt = $pdo->prepare($sql);
|
92
|
+
|
93
|
+
$stmt->bindValue(':t',$title,PDO::PARAM_STR);
|
94
|
+
|
95
|
+
$fp = fopen($_FILES['_img']['tmp_name'], 'rb');
|
96
|
+
|
97
|
+
$stmt->bindValue(":i", $fp, PDO::PARAM_LOB);
|
98
|
+
|
99
|
+
$stmt->execute();
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
```
|