Hi… I am Newbie…I want to know How can i show images at view from a directory. I am not using DB. I am trying to use fuction opendir() but I am getting an Error 500.
Hi… I am Newbie…I want to know How can i show images at view from a directory. I am not using DB. I am trying to use fuction opendir() but I am getting an Error 500.
Show a picture?
Basic HTML:
<img src="image.jpg">
Yii style:
<?= Html::img('image.jpg'); ?>
I am trying to show all images from a directory
<?php $dir = $_SERVER['SERVER_NAME'].Yii::app()->request->baseUrl."/images/porterias_infantiles"; echo $dir;
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo $file;
}
closedir($dh);
}
}
?>
$webRootPath = Yii::getAlias('@webroot') . '/uploads/images';
$webPath = Yii::getAlias('@web') . '/uploads/images';
if (file_exists($webRootPath)) {
$fileNames = array_diff(scandir($webRootPath), array('..', '.'));
foreach ($fileNames as $fileName) {
echo Html::img($webPath . '/' . $fileName);
}
}
First you need to place the images you want to display under the web tree. Let’s assume you have done that and they are in folder called Images. You can then use a Repeater control to display them by data-binding it like so:
Something like this…
<asp:Repeater ID="RepeaterImages" runat="server">
<ItemTemplate>
<asp:Image ID="Image" runat="server" ImageUrl='<%# Container.DataItem %>' />
</ItemTemplate>
</asp:Repeater>
from:www.gbridal.com