Milo111 Milo111 - 3 months ago 12
PHP Question

Complex Syntax Error php html

I have a problem with syntax error. trying to upload image from directory into my list in html but it keeps saying things like:

Parse error: syntax error, unexpected '"', expecting ',' or ';' in D:\xampp\htdocs\Waldi\index.php on line 243

<?php

$dir="img/";


if($opendir=opendir($dir)){
while(($file=readdir($opendir))!==FALSE){
if($file!="." && $file!="..")
echo '<li class="col-lg-4 col-md-4 col-sm-3 col-xs-4 col-xxs-12">
<img class="img-responsive" src='"$dir/$file"'>
</li>';
}
}
?>

Answer

It's a quote question. Try This

$dir = "img/";


if ($opendir = opendir($dir) ) {
  while ( ($file = readdir($opendir) ) !== FALSE) {
    if ($file != "." && $file != "..") {
      echo '<li class="col-lg-4 col-md-4 col-sm-3 col-xs-4 col-xxs-12">
              <img class="img-responsive" src="'.$dir.'/'.$file.'">
            </li>';
    }
  }
}