質問編集履歴

2

意図的な内容抹消の取り消し

2018/11/19 01:21

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1 +1,99 @@
1
+ PHPを学習中で、外部サイトの画像を保存するプログラムを作成しました。
2
+
3
+ まだまだ初歩段階で外部サイトの画像URLが連番の場合のみ動作する物なのですが、「file_put_contents」を使用した場合、
4
+
5
+ 数枚ならいいですが、何百の画像を保存させようとしたとき外部サーバーに負担がものすごくかかってしまうものなのでしょうか。
6
+
7
+ 負荷がかかってしまう場合、こういった保存したい物の場合、何か回避方法などあるのでしょうか?
8
+
9
+ よろしくお願いいたします。
10
+
11
+ ```ここに言語を入力
12
+
13
+ <?php
14
+
15
+ set_time_limit(0);
16
+
17
+ $error = '';
18
+
19
+ if(isset($_POST['syutoku'])){
20
+
21
+ $get_img = $_POST['number'];
22
+
23
+ $url = $_POST['url'];
24
+
25
+ if(isset($get_img) && isset($url)){
26
+
27
+ for($i=1;$i<=$get_img;$i++){
28
+
29
+ $url_img = $url . sprintf('%05d', $i).'.jpg';
30
+
31
+ $context = stream_context_create(array(
32
+
33
+ 'http' => array('ignore_errors' => true)
34
+
35
+ ));
36
+
37
+ $img = file_get_contents($url_img,false,$context);
38
+
39
+ $imginfo = pathinfo($url_img);
40
+
41
+ $img_name = $imginfo['basename'];
42
+
43
+ file_put_contents('./img/' . $img_name, $img);
44
+
45
+ }
46
+
47
+ }else{
48
+
49
+ $error = 'フォームに値を入力してください。';
50
+
51
+ }
52
+
53
+ }
54
+
55
+ ?>
56
+
57
+ <!DOCTYPE html>
58
+
59
+ <html>
60
+
61
+ <head>
62
+
63
+ <meta charset="UTF-8">
64
+
65
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
66
+
1
- tesutottttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
67
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
68
+
69
+ <title>外部サイト画像ダウンロード</title>
70
+
71
+ </head>
72
+
73
+ <body>
74
+
75
+ <h1>外部サイト画像ダウンロード</h1>
76
+
77
+ <p>取得する外部サイトURLと画像の最大ファイル数字を入力してください。</p>
78
+
79
+ <?php if($error){
80
+
81
+ echo '<p>' .$error. '</p>';
82
+
83
+ } ?>
84
+
85
+ <form method="post" action="index.php">
86
+
87
+ <p>サイトURL:<input type="text" value="" name="url"></p>
88
+
89
+ <p>最大数字:<input type="text" value="" name="number"></p>
90
+
91
+ <p><input type="submit" name="syutoku" value="画像取得"></p>
92
+
93
+ </form>
94
+
95
+ </body>
96
+
97
+ </html>
98
+
99
+ ```

1

tesuto

2018/11/19 01:21

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,105 +1 @@
1
- PHPを学習中で、外部サイトの画像を保存するプログラムを作成しました。
2
-
3
- まだまだ初歩段階で外部サイトの画像URLが連番の場合のみ動作する物なのですが、「file_put_contents」を使用した場合、
4
-
5
- 数枚ならいいですが、何百の画像を保存させようとしたとき外部サーバーに負担がものすごくかかってしまうものなのでしょうか。
6
-
7
- 負荷がかかってしまう場合、こういった保存したい物の場合、何か回避方法などあるのでしょうか?
8
-
9
- よろしくお願いいたします。
10
-
11
-
12
-
13
- ```ここに言語を入力
14
-
15
- <?php
16
-
17
- set_time_limit(0);
18
-
19
- $error = '';
20
-
21
- if(isset($_POST['syutoku'])){
22
-
23
- $get_img = $_POST['number'];
24
-
25
- $url = $_POST['url'];
26
-
27
- if(isset($get_img) && isset($url)){
28
-
29
- for($i=1;$i<=$get_img;$i++){
30
-
31
- $url_img = $url . sprintf('%05d', $i).'.jpg';
32
-
33
- $context = stream_context_create(array(
34
-
35
- 'http' => array('ignore_errors' => true)
36
-
37
- ));
38
-
39
- $img = file_get_contents($url_img,false,$context);
40
-
41
- $imginfo = pathinfo($url_img);
42
-
43
- $img_name = $imginfo['basename'];
44
-
45
- file_put_contents('./img/' . $img_name, $img);
46
-
47
- }
48
-
49
- }else{
50
-
51
- $error = 'フォームに値を入力してください。';
52
-
53
- }
54
-
55
- }
56
-
57
- ?>
58
-
59
- <!DOCTYPE html>
60
-
61
- <html>
62
-
63
- <head>
64
-
65
- <meta charset="UTF-8">
66
-
67
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
68
-
69
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
1
+ tesutottttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
70
-
71
- <title>外部サイト画像ダウンロード</title>
72
-
73
- </head>
74
-
75
- <body>
76
-
77
- <h1>外部サイト画像ダウンロード</h1>
78
-
79
- <p>取得する外部サイトURLと画像の最大ファイル数字を入力してください。</p>
80
-
81
- <?php if($error){
82
-
83
- echo '<p>' .$error. '</p>';
84
-
85
- } ?>
86
-
87
- <form method="post" action="index.php">
88
-
89
- <p>サイトURL:<input type="text" value="" name="url"></p>
90
-
91
- <p>最大数字:<input type="text" value="" name="number"></p>
92
-
93
- <p><input type="submit" name="syutoku" value="画像取得"></p>
94
-
95
- </form>
96
-
97
-
98
-
99
- </body>
100
-
101
- </html>
102
-
103
-
104
-
105
- ```