I try to get all the images from a folder with this code. the result is not correct because the code echo a "/" too much (just like below)

Someone please help!

        $dirname = 'uploads/'.$email.'/'.$product_id.'/';
        $images = glob($dirname."*");

        foreach($images as $image) {
            echo '<img src="'.$image.'" /><br />';
        }


<img src="uploads/test@test.com//52">

This is the desired result:

<img src="uploads/test@test.com/52/">

This is the final result..

Thank to Rakesh Shetty thank you!

$product_id = $row['product_id'];
$dirname = 'uploads/'.$email.'/'.$product_id.'/';

$files = glob($dirname."*.*");

print_r($files); // check what you get

    for ($i=1; $i<count($files); $i++){
      $num = $files[$i];
      echo '<img src="'.$num.'" /> ';
}

print_r($files);
有帮助吗?

解决方案

Try this : Source

$dirname = 'uploads/'.$email.'/'.$product_id.'/';

$files = glob($dirname."*.*");

print_r($files); // check what you get


    for ($i=1; $i<count($files); $i++)
    {

      $num = $files[$i];
      echo '<img src="'.$num.'" /> ';


    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top