Outdated call forwarding?

I read on many forums about removing ampersand (&) before any $ specified in a variable, and I did, but it removes the functionality of the code used. What should I do?

Demo is here .

The code is here:

<?php $val = $_GET['name']; $path = "./images/".$val."/"; $file_array = array (); readThisDir ( $path, &$file_array ); echo '<div class="gallery" style="display:block;" id="'.$val.'">'; echo '<ul>'; foreach ( $file_array as $file ) { if (strstr($file, "png")||strstr($file, "jpg")||strstr($file, "bmp")||strstr($file, "gif")) { list($width, $height) = getimagesize($file); $info = exif_read_data($file); echo '<li><a href="javascript:void(0);"><img src="'.$file.'" width="'.$width.'" height="'.$height.'" alt="'.$file.'"/></a><span>'.$info['Title'].'<div class="gallerynav"><a href="javascript:void(0);" class="prevproject">&laquo;</a><a href="javascript:void(0);" class="nextproject">&raquo;</a></div></span></li>'; } } echo '</ul>'; echo '</div>'; function readThisDir ( $path, $arr ) { if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir ( $path."/".$file )) { readThisDir ($path."/".$file, &$arr); } else { $arr[] = $path."/".$file; } } } closedir($handle); } } ?> 
0
php
source share
4 answers

You should mark the missing link in the function declaration, and not where the function is called.

 ... function readThisDir ( $path, &$arr ) { ... 
+7
source share

Edit

 function readThisDir ( $path, $arr ) 

For

 function readThisDir ( $path, &$arr ) 

and

 readThisDir ($path."/".$file, &$arr); 

For

 readThisDir ($path."/".$file, $arr); 

PHP doesn't want you to pass the address of a variable directly to a function.

+3
source share

It does not answer your question directly, but you can replace all this code with the following (suppose 5.2+) using RecursiveDirectoryIterator

 $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path); ); $files = array(); foreach ($it as $file) { $files[] = $file->getPathname(); } 
+2
source share

Make the readThisDir function to return an array with the file information filled in and assign it to the $ file_array variable. something like:

 $file_array = readThisDir ($path); function readThisDir ( $path) { $arr = array (); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir ( $path."/".$file )) { readThisDir ($path."/".$file, &$arr); } else { $arr[] = $path."/".$file; } } } closedir($handle); } return $arr; } 
0
source share

All Articles