簡體   English   中英

使用Javascript或PHP從網頁保存圖像

[英]Save Images from a webpage using Javascript or PHP

我用jquery編寫了一個小javascript應用程序,它通過Google Feed API獲取rss feed並將其顯示為圖像網格。

代碼如下:

<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);
}

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM