0

I want to display the image and the image url of a directory
I found this code, but there is a dot before the filename.

<?php
$files = glob("./images/*.*");
for ($i=0; $i<count($files); $i++) {
    $image = $files[$i];
    print "<textarea>";
    print "http://" .$_SERVER['SERVER_NAME'].$image;
    print "</textarea>"."<br />";
    echo '<img src="'.$image .'" />'."<br /><br />";    
}
?>

the result will be like this :

<textarea>http://domain.com./images/filename.png<textarea>
<img src="./images/filename.png" />

please help to fix this. thanks.

1

1 Answer 1

2

I solved the problem by using the following:

<?php
$files = glob("images/*.*");
for ($i=0; $i<count($files); $i++) {
    $image = $files[$i];
    echo '<img src="'.$image .'" />'."<br /><br />";   
    print "<textarea>";
    print "http://" .$_SERVER['SERVER_NAME'].$image;
    print "</textarea>"."<br /><br /><br />"; 
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.