Array Images

Permalink
Php:-
$dir = 'images/';
$images_array = glob($dir.'*.jpg');
foreach (($images_array) as $v){
echo '<a href="'.$v.'"><img src="'.$v.'" width="60" height="60" /></a>&nbsp;';
}

Concrete5:- ? in view.php

Please anyone can help

Thanks

John

 
JSA1972 replied on at Permalink Reply
Concrete5 view.php

$dir = $this->getBlockURL()."/images/";
$images_array = glob( $dir.'*.jpg');
foreach (($images_array) as $v){
echo '<a href="$v"><img src="$v" width="60" height="60" /></a>&nbsp;';
}

I have tried but not working. What I have wrong?

I think from wrong line of foreach or the var $images_array. but I am not sure.
noXstyle replied on at Permalink Best Answer Reply
noXstyle
Try:
$dir = $_SERVER['DOCUMENT_ROOT'].$this->getBlockURL()."/images/";
$images_array = glob( $dir.'*.jpg');
foreach (($images_array) as $v){
    echo '<a href="'. str_replace($_SERVER['DOCUMENT_ROOT'],'',$v).'"><img src="'. str_replace($_SERVER['DOCUMENT_ROOT'],'',$v).'" width="60" height="60" /></a>&nbsp;';
}


Theres couple of problems with your code:
1. The dir name starts from document root, no idea about windows servers but on unix php tries to get the file structure starting from system root, thus the document root variable. Also, while constructing the image url, the document root should not be there, thus the str_replace()
2. Variables do not evaluate with single quotes.

Hope it helps.
JSA1972 replied on at Permalink Reply
Thanks for your reply.

I have followed your answer but no working. Have you tired to test?

John
mkly replied on at Permalink Reply
mkly
If we knew a little more about where you are calling this from we may be able to be a bit more help. One tip is that DIR_BASE should be the root directory of your installation.

EDIT: There are quite a few view.php's in Concrete5
JSA1972 replied on at Permalink Reply
Thanks Mkly I have tried but still not working. I am solving the problem. Is possible controlled.php for function to view?
mkly replied on at Permalink Reply
mkly
I hate to repeat myself but if you explain where you are calling this from and what you are trying to do I can be more help. I didn't actually suggest you try anything because I am unable to guess at what you are trying to do.
noXstyle replied on at Permalink Reply
noXstyle
I would put my money on some block's view.php since hes using getBlockURL(). It's either that or I've been dead wrong to begin with.

Anyhow can you paste the source you're getting from that or a var_dump() of your dir and images_array variables?
JSA1972 replied on at Permalink Reply
Hi again

Sorry Mkly you hate repeat.

I have been learned from php str_replace. My quite understand for the problem.

Arrays are working but the a href and img scr are wrong path. You are nearly right.

The locate says "http://****/home/***/public_html/***/concrete/blocks/images/1.jpg

How can remove the locate home from str_replace?
mkly replied on at Permalink Reply
mkly
Good luck with your issue.
JSA1972 replied on at Permalink Reply
Thank you very much for both help.

I have replaced to :-
<a href="<?php echo str_replace($_SERVER['DOCUMENT_ROOT'],' ',$v); ?>"><img src="<?php str_replace($_SERVER['DOCUMENT_ROOT'],' ',$v); ?>" width="60" height="60" /></a>

They are working with arrays as clicking them to pictures but no display of the links images.