javascript - jQuery 从外部源下载图像

标签 javascript php jquery

我有一个链接,例如:

http://vignette4.wikia.nocookie.net/2007scape/images/c/c1/3rd_age_amulet.png/revision/latest?cb=20141217224859

我想使用 jQuery/javascript 将其下载到具有特定名称的特定文件夹中。

有什么解决办法吗?我找不到任何引用它的东西 - 我不知道从哪里开始,因为这是我第一次尝试这样的事情。

如果有人能指出我正确的方向吗?

我当前有一个从外部资源加载到页面中的图像列表:

num.txt

3rd age amulet
3rd age full helmet
3rd age kiteshield
3rd age mage hat
3rd age platebody
3rd age platelegs
3rd age range coif
3rd age range legs
3rd age range top
3rd age robe top
3rd age robe
3rd age vambraces
3rd age longsword
3rd age bow
3rd age wand
3rd age cloak

转储器.php

$file = "num.txt";
$focus = "https://2007.runescape.wikia.com/wiki/";
foreach(file("../resources/items/names/$file") as $line) {
    $item_name = str_replace(" ", "_", $line);
    $url = $focus . $item_name;
    $fc = file_get_contents($url);
    echo get_between("<td colspan=\"2\" style=\"text-align: center;\">", "Release date", $fc);
}

function get_between($start, $end, $subject) {
    $temp1 = strpos($subject, $start) + strlen($start);
    $result = substr($subject, $temp1, strlen($subject));
    $dd = strpos($result, $end);
    if($dd == 0) {
        $dd = strlen($result);
    }
    return substr($result, 0, $dd);
}

tl;dr:我的页面上现在加载了一堆图像,我可以使用 jQuery 访问它们:

<script>
$("img").each(function() {
    console.log(this.src);
})
</script>

我想将其中每一个下载到具有特定文件名的文件夹中。

最佳答案

您可以从图像创建 zip 文件并下载它(通过 js)。

关于javascript - jQuery 从外部源下载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31727039/

相关文章:

php - 没有 Suhosin 的 php 5.4 安全吗?

javascript - 将 onclick 与 Google Analytics 结合使用并在新选项卡中打开

javascript - 是否省略非捕获组? : have a negative effect on RegExp.原型(prototype).测试()?

javascript - 在 javascript 中从类似 "20161126 00:00"的字符串创建日期

php - 我什么时候想使用 .html 而不是 .php 作为文件扩展名?

jquery - 替换后事件未注册

java - 如何让 ScriptEngine 运行多个 javascript 文件?

php - 如何使用 php system() 函数正确运行 mysql 命令?

javascript - 每行不同的文本 Jquery Modal/Dialog 表单

javascript - 使用铁路由器后 meteor 模板助手不工作