forked from owner888/phpspider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YangZetao
authored and
YangZetao
committed
Sep 25, 2016
1 parent
dc306a0
commit 1bce83a
Showing
4 changed files
with
61 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
ini_set("memory_limit", "1024M"); | ||
require dirname(__FILE__).'/../core/init.php'; | ||
|
||
/* Do NOT delete this comment */ | ||
/* 不要删除这段注释 */ | ||
|
||
$spider = new phpspider(); | ||
|
||
$spider->on_attachment_file = function($attachment_url, $fileinfo) | ||
{ | ||
// 输出文件URL地址和文件类型 | ||
//var_dump($attachment_url, $fileinfo); | ||
|
||
if ($fileinfo['fileext'] == 'jpg') | ||
{ | ||
// 以纳秒为单位生成随机数 | ||
$filename = uniqid(); | ||
// 在data目录下生成图片 | ||
$filepath = PATH_DATA."/{$filename}.jpg"; | ||
// 用系统自带的下载器wget下载 | ||
exec("wget {$attachment_url} -O {$filepath}"); | ||
|
||
// 用PHP函数下载,容易耗尽内存,慎用 | ||
//$data = file_get_contents($attachment_url); | ||
//file_put_contents($filepath, $attachment_url); | ||
} | ||
}; | ||
|
||
$url = "http://ocnt0imhl.bkt.clouddn.com/imgs/1637/2015-07/k306n1wzvkq669nm.jpg?token=xxx"; | ||
$spider->request_url($url); |