我有一个包含图片网址的表格,如下所示:
Table:
partno | url
10878 | http://www.pic1.jpg
20477 | http://www.pic2.jpg
and so on (+10000)
我想运行一个脚本,以便在我的LOCAL路径上下载所有这些脚本
我很困惑这可能是最简单的方法。我想运行一个PHP脚本,以便从MySQL获取URL,然后使用PHP命令下载每个脚本,就像这样...请帮帮我
下面..我已经通过使用文本框搜索和下载逐个下载图像
// 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>
答案 0 :(得分:0)
我不确定我是否理解正确,但你可以通过下面的源代码从mysql获取你的文件URL。这会将您的数据存储在$ row中,您可以使用它。并且它回显了整个$行,因此您可以看到查询的结果。
<?php
$link = mysql_connect('localhost', 'username', 'password');
$db_selected = mysql_select_db('database_name', $link);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$result = mysql_query('SELECT partno, url FROM table_name');
if (!$result) {
die('Error: ' . mysql_error());
}
//to show what the query got
while ($row = mysql_fetch_assoc($result)) {
echo ("name: ").$row['partno'].("<br>");
echo ("url: ").$row['url'].("<br>");
}
//to store the data in $row
$row = mysql_fetch_assoc($result)
mysql_close($link);
?>
答案 1 :(得分:0)
我建议您使用python执行此任务并编写以下代码
import MySQLdb
import urllib
con = MySQLdb.Connect('server', 'username', 'password', 'database')
cursor = con.cursor()
query = "SELECT url FROM table"
cursor.execute(query)
result = cursor.fetchall()
for url in result:
urllib.urlretrieve(url[0], "local/address/filename")