我有一個產品形象從URL將圖像複製到服務器,刪除所有圖像後
http://www.myaffiliate.com/products/product.jpg
我要複製的想象到我的網站,在一個文件夾,名爲讓我們說產品的推廣鏈接。它託管在共享的sherver上,而不是我的電腦上。我認爲PHP副本()不起作用,試用了它,我認爲我的主機不支持該方法。我怎麼能這樣做,捲曲也許?然後,我需要一個php命令來刪除產品文件夾中的所有圖像 - 我將使用cronjob完成此操作。在你希望你的服務器上的文件
<?php
$table = 'cron';
$feed = 'myfeed';
$xml = simplexml_load_file($feed);
mysql_query("TRUNCATE TABLE ".$table."", $dbh1);
mysql_query("TRUNCATE TABLE ".$table."", $dbh2);
function getimg($url) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$user_agent = 'php';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
foreach($xml->performerinfo as $performerinfo)
{
$performerid = $performerinfo->performerid;
$category = $performerinfo->category;
$subcategory = $performerinfo->subcategory;
$bio = $performerinfo->bio;
$turnons = $performerinfo->turnons;
$willing = $performerinfo->willingness;
$willingness = str_replace(',', ', ', $willing);
$age = $performerinfo->age;
$build = $performerinfo->build;
$height = $performerinfo->height;
$weight = $performerinfo->weight;
$breastsize = $performerinfo->breastsize;
$haircolor = $performerinfo->haircolor;
$hairlength = $performerinfo->hairlength;
$eyecolor = $performerinfo->eyecolor;
$ethnicity = $performerinfo->ethnicity;
$sexpref = $performerinfo->sexpref;
$pic0 = $performerinfo->picture[0];
$pic1 = $performerinfo->picture[1];
$pic2 = $performerinfo->picture[2];
$pic3 = $performerinfo->picture[3];
$pic4 = $performerinfo->picture[4];
$test = $performerinfo->picture[0];
$imgurl = 'http://www.foodtest.ru/images/big_img/sausage_3.jpg';
$imagename= basename($imgurl);
if(file_exists('./tmp/'.$imagename)){continue;}
$image = getimg($imgurl);
file_put_contents('tmp/'.$imagename,$image);
}
//baracuda reloaded
mysql_query("TRUNCATE TABLE reloaded", $dbh1);
mysql_query("TRUNCATE TABLE reloaded", $dbh2);
mysql_query("INSERT INTO reloaded SELECT * FROM ".$table."", $dbh1);
mysql_query("INSERT INTO reloaded SELECT * FROM ".$table."", $dbh2);
?>
想要在下載圖像後刪除圖像正確嗎?如果是這樣,請調用unlink($ filename);在每個圖像上。與下面的Lawrence Cherone的腳本一起使用。 – 2011-05-14 14:07:56
您使用相同的圖像網址,因此每次迭代都會調用相同的圖像,同樣,如果Feed中有很多或條目,那麼無論如何,在sql查詢中使用更多的邏輯將會加快速度,如果您檢查是否條目已添加等。 – 2011-05-14 14:47:08