gpt4 book ai didi

javascript - 使用 Javascript 或 PHP 从网页保存图像

转载 作者:行者123 更新时间:2023-11-30 06:05:08 24 4
gpt4 key购买 nike

我用 jquery 编写了一个小的 javascript 应用程序,它通过 Google Feed API 获取 rss 提要并将其显示为图像网格。

代码看起来像:

<ul>
...
<li><a class="entry" href="LINK_TO_BIG_IMAGE" title="TITLE_OF_ENTRY"><img class="entry-img" src="THUMB_IMG" alt="" /></a></li>
...
</ul>

我想要做的是能够将所有图像一次保存在服务器上的一个文件夹中。现在,如果它在页面加载时执行,我会很高兴。可以通过 Javascript 吗?你有什么方向可以指点我吗?

提前致谢!

最佳答案

您关于将路径提交到服务器上的 php 脚本的评论会起作用(我不建议这样做,但它会起作用)。

然后您的 php 可以像这样下载图像(未经测试,您需要在保存文件时从 $url 解析文件名)。

<?php

$image_urls = isset($_POST['image_urls']) ? $_POST['image_urls'] : null;//assume it's an array of urls

if (!count($image_urls))//check that our array actually contains 1 or more urls
{
die('no urls provided');
}

$image_folder_path = '/home/somefolder/';

foreach ($image_paths as $index => $url)
{
$file_name = $image_folder_path . $index . '.jpg';//you will need to parse the url for the file name and extension for this to be accurate

$image = file_get_contents($url);//if fopen wrappers is enabled you can do this otherwise use something like cUrl to fetch the file
file_put_contents($file_name, $image);
}

?>

关于javascript - 使用 Javascript 或 PHP 从网页保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5452061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com