我得到了一個從目錄到mysql插入腳本的工作映像。問題是我在每個目錄後需要更改腳本本身的名稱從其他目錄插入下一個圖像。每個文件和每個diretory與圖像是在一個名爲「圖像」prent目錄。所以我的問題我怎麼能說從這個目錄中插入一切在MySQL數據庫中,並使用該目錄的名稱作爲其中的圖像的類別名稱。如何提高使用php批量mysql插入從目錄一次抓取所有目錄和圖像
<?php
$server = 'xxxxx';
$dbuser = 'xxxxxx';
$dbpass = 'xxxxxx';
$dbname = 'xxxxxxx';
$connect = mysql_connect($server,$dbuser,$dbpass);
mysql_select_db($dbname,$connect);
$path = "images/thanks/";
$files = array_map('mysql_real_escape_string',array_filter(glob("{$path}*.*"),'is_file'));
if(empty($files)){
echo "There were no matching files to insert into the database.";
} else {
$insertValues = array();
foreach($files as $file)
{
$data = getimagesize($file);
$width = $data[0];
$height = $data[1];
$insertValues[] = "('Titel', 'thanks', '{$file}', '$width', '$height')";
}$query = "INSERT INTO `gbpics` (`gbpictitel`, `gbpiccat`, `gbpicurl`, `gbpicwidth`, `gbpicheight`) VALUES " . implode(', ', $insertValues);
if(!mysql_query($query)){
echo "There was a problem inserting the data.";
trigger_error("Query failed: $query<br />Error: " . mysql_error());
} else {
echo "The data was inserted successfully.";
}
}?>
我強烈建議你在代碼審查第一張貼此。 – hakre