2017-06-19 23 views
0

您好我的批量圖像插入腳本爲mysql isnt working.i無法找出原因。 我有根目錄中的上傳腳本和一個名爲img的文件夾中的圖像在這個文件夾中的一個文件夾名稱與圖像類別的圖像,所以插入到mysql.but他說我每次「沒有匹配的文件插入到數據庫「。不知道爲什麼我認爲路徑應該沒問題。批量圖像從多個文件夾與文件夾中的圖像將無法工作

這裏是腳本傢伙

$connect = mysql_connect($server,$dbuser,$dbpass); 
mysql_select_db($dbname,$connect); 




$dirs = array_filter(glob('img/*'), 'is_dir'); 
foreach ($dirs as $dir) { 
    $path = "img/" . $dir . "/"; 
    $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', {$dir}, '{$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."; 
     } 
    } 
} 
?> 
+0

你試過相對路徑嗎? '''$ path =「./img/」。 $ dir。 「/」;''' –

+0

@SloanThrasher是的,試過了不工作 –

+0

@SloanThrasher任何其他的想法? –

回答

1

我覺得

$path = "img/" . $dir . "/"; 

被複制IMG /一部分。 可能應該是

$path = $dir . "/"; 
+0

現在路徑是正確的,但仍然不起作用 –

+0

總是會讓它更容易獲得比'不工作'更多的內容,但也注意到'$ insertValues [] =「('Titel','{$ dir} ','{$ file}','$ width','$ height')「;' –