Welcome Guest, Not a member yet? Register   Sign In
Why this page keeps loading?
#1

[eluser]behnampmdg3[/eluser]
Hello;

This script reads files from a directory and shows the names. It works fine, shows all the content properly but it keeps loading the page over and over (the browser reload botton keeps turning).

What am I doing wrong? Should I somehow close the foreach or something like that?

Thanks

Code:
$directory_url = "/home/nickdavi/public_html/upload/server/php/files/thumbnail";
$this->load->helper('directory');
$files = directory_map($directory_url);
foreach($files as $photo)
{
  ?&gt;<img src="/files/thumbnail/&lt;?php echo $photo;?&gt;"  margin-right:5px;"/>&lt;?php
  
}
#2

[eluser]PhilTem[/eluser]
1) Directories should always contain a trailing slash =>
Code:
$directory_url = "/home/nickdavi/public_html/upload/server/php/files/thumbnail/";

2) I don't have any other idea expect that you maybe have thousands of files in that directory and it takes some time echoing the links/images Wink
#3

[eluser]behnampmdg3[/eluser]
[quote author="PhilTem" date="1358019887"]1) Directories should always contain a trailing slash =>
Code:
$directory_url = "/home/nickdavi/public_html/upload/server/php/files/thumbnail/";

2) I don't have any other idea expect that you maybe have thousands of files in that directory and it takes some time echoing the links/images Wink[/quote]Hello; I added the slash but it didn't work.
/home/nickdavi/public_html/sincity/website_admin/upload/server/php/files/thumbnail/

There are about 15 files in the folder.
#4

[eluser]CroNiX[/eluser]
Why all of the opening/closing php tags within the loop?

Try using php alternative syntax.
Code:
$files = directory_map($directory_url);
//close php tag
?&gt;
&lt;?php foreach($files as $photo): ?&gt;
  <img src="/files/thumbnail/&lt;?php echo $photo;?&gt;"/>  
&lt;?php endforeach; ?&gt;

Also note that your margin-right isn't in any sort of a style tag and it's missing a quote...which is probably your real problem because you aren't outputting valid HTML.
It should probably be:
Code:
<img src="/files/thumbnail/&lt;?php echo $photo;?&gt;"  />
#5

[eluser]CroNiX[/eluser]
nevermind, this forum software is eating part of the post so I can't write it as it should be. Nice.
#6

[eluser]behnampmdg3[/eluser]
[quote author="CroNiX" date="1358029149"]nevermind, this forum software is eating part of the post so I can't write it as it should be. Nice.[/quote]Didn't work but thank you for your help. I changed it to what you suggested but still the same!
Code:
&lt;?php
$this->load->helper('directory');
$files = directory_map(PHOTO_GALLERY_POOL);
?&gt;

&lt;?php foreach($files as $photo): ?&gt;  

  <div  margin-right:5px">
        <img src="http://nickdavis.com.au/sincity/website_admin/upload/server/php/files/thumbnail/&lt;?php echo $photo;?&gt;"/>
  <br />&lt;input type="checkbox" name="photo[]" value="&lt;?php echo $photo;?&gt;" title="&lt;?php echo $photo;?&gt;" /&gt;
  </div>
  
&lt;?php endforeach; ?&gt;
#7

[eluser]InsiteFX[/eluser]
Because you should have the files code in your controller then pass them to the view using $data then
use the foreach loop to display them.
#8

[eluser]behnampmdg3[/eluser]
[quote author="InsiteFX" date="1358031522"]Because you should have the files code in your controller then pass them to the view using $data then
use the foreach loop to display them.
[/quote]Hey thanks but it didn't work!

View
Code:
&lt;?php foreach($files as $photo): ?&gt;  

  <div  margin-right:5px">
        <img src="&lt;?php echo PHOTO_GALLERY_POOL_LOCATION.$photo;?&gt;"/>
  <br />&lt;input type="checkbox" name="photo[]" value="&lt;?php echo $photo;?&gt;" title="&lt;?php echo $photo;?&gt;" /&gt;
  </div>
  
&lt;?php endforeach; ?&gt;
Controller
Code:
$this->load->helper('directory');
$data['files'] = directory_map(PHOTO_GALLERY_POOL);
Any more ideas?
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB