ฉันต้องการรายการ URL ของไฟล์ทั้งหมดในฟิลด์ฐานข้อมูลของฉัน
ฐานข้อมูล mysql, article
ตาราง
`id` | `subject` | `content`
ค่า content
คือข้อความ html ที่มี URL ไฟล์อย่างน้อย 1 รายการ เช่น:
<p>this is the answer for ..., you can refer to below screenshot:</p>
<img src="http://the_url_of_image_here/imagename.jpg/>
<p>or refer to below document</p>
<a href="http://the_url_of_doc_here/guide.ppt>guide</a>
<a href="http://the_url_of_doc_here/sample.dox>sample</a>
ไฟล์มี 2 ประเภท
- รูปภาพพร้อมนามสกุล jpg,jpeg,png,bmp,gif
- เอกสารที่มีนามสกุล doc,docx,ppt,pptx,xls,xlsx,pdf,xps
ฉันทำ goolge เยอะมาก ดูเหมือนว่ามันยากที่จะทำเฉพาะกับ mysql, php จะทำให้มันง่าย ฉันเขียนโค้ดแต่มันไม่สามารถทำงานได้
ขอบคุณ cars10 ฉันแก้ไขมันได้แล้ว
function export_articles_link()
{
global $date_from, $date_to;
$filename = "kb_articles_link_".$date_from."_".$date_to.".xlsx";
header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$query = 'SELECT `content` FROM `kb_articles` WHERE ((DATE(`dt`) BETWEEN \'' . $date_from . '\' AND \'' . $date_to . '\') AND (`content` LIKE \'%<img src=%\' or `content` LIKE \'%<a href="http:%\')) order by id asc';
$result = mysql_query($query);
$writer = new XLSXWriter();
$img_list = array();
while ($row=mysql_fetch_array($result))
{
$text = $row['content'];
preg_match_all('!http://.+\.(?:jpe?g|png|gif|ppt?|xls?|doc?|pdf|xdw)!Ui', $text, $matches);
$img_list = $matches[0];
foreach ($img_list as $url)
{
$writer->writeSheetRow('Sheet1', array($url)); // if more than one url it will be put on first column
}
};
$writer->writeToStdOut();
exit(0);
}
แบ่งปันกับผู้อื่นที่ต้องการตัวอย่างงาน หวังว่าจะช่วยประหยัดเวลาของคุณ