批量图像从多个文件夹与文件夹中的图像将无法工作

问题描述:

您好我的批量图像插入脚本为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任何其他的想法? –

我觉得

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

被复制IMG /一部分。 可能应该是

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

现在路径是正确的,但仍然不起作用 –

+0

总是会让它更容易获得比'不工作'更多的内容,但也注意到'$ insertValues [] =“('Titel','{$ dir} ','{$ file}','$ width','$ height')“;' –