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> ';
}
Concrete5:- ? in view.php
Please anyone can help
Thanks
John
$dir = 'images/';
$images_array = glob($dir.'*.jpg');
foreach (($images_array) as $v){
echo '<a href="'.$v.'"><img src="'.$v.'" width="60" height="60" /></a> ';
}
Concrete5:- ? in view.php
Please anyone can help
Thanks
John
Try:
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.
$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> '; }
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.
Thanks for your reply.
I have followed your answer but no working. Have you tired to test?
John
I have followed your answer but no working. Have you tired to test?
John
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
EDIT: There are quite a few view.php's in Concrete5
Thanks Mkly I have tried but still not working. I am solving the problem. Is possible controlled.php for function to view?
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.
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?
Anyhow can you paste the source you're getting from that or a var_dump() of your dir and images_array variables?
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?
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?
Good luck with your issue.
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.
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.
$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> ';
}
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.