【发布时间】:2017-01-03 11:09:51
【问题描述】:
我有一个包含图片 URL 的表格,如下所示:
Table:
partno | url
10878 | http://www.pic1.jpg
20477 | http://www.pic2.jpg
and so on (+10000)
我想运行一个脚本,以便将它们全部下载到我的本地路径
我很困惑什么可能是最简单的方法。我想运行一个 PHP 脚本以从 MySQL 获取 URL,然后使用 PHP 命令下载每个 URL,类似这样...请帮助我
下面..我已经通过使用文本框搜索和下载完成了一张下载图片
// Open the file to get existing content
$data = file_get_contents($file);
$newimage=basename($file);
// New file
$new = 'image/'.$newimage;
// Write the contents back to a new file
file_put_contents($new, $data);
mysql_query("Insert into image set name = '$newimage' ");
echo "<img src='image/$newimage' width='300px' height='250px'/>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="url" name="url"/><br/><br/>
<input type="submit" name="subimg" value="submit"/>
</form>
从存储在数据库代码中的 URL 下载多个图像..但是输出不会来..请帮助我
<?php
// connection to database
$con = mysql_connect("localhost","root","");
mysql_select_db('import_exceldata',$con)
?>
<?php
if(isset($_REQUEST['subimg']))
{
$result=mysql_query("select url from mytask ");
set_time_limit(1000);
while( $url = $result->fetch() ) {
// Open the file to get existing content
$data = file_get_contents($result);
$newimage=basename($result);
// New file
$new = 'image/'.$newimage;
// Write the contents back to a new file
file_put_contents($new, $data);
}
mysql_query("Insert into image set name = '$newimage' ");
echo "<img src='image/$newimage' width='300px' height='250px'/>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="submit" name="subimg" value="retrieve images"/>
</form>
【问题讨论】:
-
但你的不明白..我想从数据库中获取多个 url 并下载图片
-
在 php 中编写一个脚本,该脚本将连接到 mysql 数据库并获取一个数组中的所有 url。现在迭代这个数组并使用 cURL 一个一个地获取每个 url
-
现在是 2017 年。PHP 的 mysql_ API 有效;几年前已弃用。
-
所以...我能做什么#Strawberry