質問編集履歴
3
aa
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
a
|
test
CHANGED
@@ -1,73 +1 @@
|
|
1
|
-
今はsimple_html_domでやろうとしていて
|
2
|
-
|
3
|
-
取得した画像をmysqlにinsertしようとしているのですがうまくいきません。
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
いい方法があればお願いします。
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
require_once('./simple_html_dom.php');
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
$html = file_get_html('http://なにか');
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
foreach ($html->find('a') as $link_path) {
|
22
|
-
|
23
|
-
$img_path = $link_path->getAttribute('href');
|
24
|
-
|
25
|
-
if (preg_match('/\.jpg$|\.png$|\.jpeg$/', $img_path)) {
|
26
|
-
|
27
|
-
daikon($img_path);
|
28
|
-
|
29
|
-
}
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
function daikon($img_path){
|
36
|
-
|
37
|
-
|
1
|
+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
38
|
-
|
39
|
-
if ($img_info[0] >= 400 && $img_info[1] >= 400) {
|
40
|
-
|
41
|
-
$extension = explode('.', $img_path);
|
42
|
-
|
43
|
-
$img_ext = end($extension);
|
44
|
-
|
45
|
-
$upload_name = sha1(date('Y-m-d H:i:s').$img_path).'.'.$img_ext;
|
46
|
-
|
47
|
-
$img_data = file_get_contents($img_path);
|
48
|
-
|
49
|
-
file_put_contents('./'.$upload_name,$img_data);
|
50
|
-
|
51
|
-
}
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
$pdo = new PDO('mysql:host=hostname; dbname=dbname', 'user', 'passward');
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
$stmt = $pdo->prepare("INSERT INTO table (name) VALUES(?)");
|
62
|
-
|
63
|
-
$stmt->execute(array("$img_data"));
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
このようにするとFTPにだけ画像が保存されます。
|
70
|
-
|
71
|
-
なお、実行するとエラーはでません
|
72
|
-
|
73
|
-
よろしくお願いします
|
2
誤字訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
このようにするとFTP
|
69
|
+
このようにするとFTPにだけ画像が保存されます。
|
70
70
|
|
71
71
|
なお、実行するとエラーはでません
|
72
72
|
|
1
コードの記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,3 +5,69 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
いい方法があればお願いします。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
require_once('./simple_html_dom.php');
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
$html = file_get_html('http://なにか');
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
foreach ($html->find('a') as $link_path) {
|
22
|
+
|
23
|
+
$img_path = $link_path->getAttribute('href');
|
24
|
+
|
25
|
+
if (preg_match('/\.jpg$|\.png$|\.jpeg$/', $img_path)) {
|
26
|
+
|
27
|
+
daikon($img_path);
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
function daikon($img_path){
|
36
|
+
|
37
|
+
$img_info = getimagesize($img_path);
|
38
|
+
|
39
|
+
if ($img_info[0] >= 400 && $img_info[1] >= 400) {
|
40
|
+
|
41
|
+
$extension = explode('.', $img_path);
|
42
|
+
|
43
|
+
$img_ext = end($extension);
|
44
|
+
|
45
|
+
$upload_name = sha1(date('Y-m-d H:i:s').$img_path).'.'.$img_ext;
|
46
|
+
|
47
|
+
$img_data = file_get_contents($img_path);
|
48
|
+
|
49
|
+
file_put_contents('./'.$upload_name,$img_data);
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
$pdo = new PDO('mysql:host=hostname; dbname=dbname', 'user', 'passward');
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
$stmt = $pdo->prepare("INSERT INTO table (name) VALUES(?)");
|
62
|
+
|
63
|
+
$stmt->execute(array("$img_data"));
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
このようにするとFTPところにだけ保存されます。
|
70
|
+
|
71
|
+
なお、実行するとエラーはでません
|
72
|
+
|
73
|
+
よろしくお願いします
|