Space in path ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Space in path ?

Post by Peuplarchie »

Good day to you all,
I'm having a proble, in the following code, all image with espace in the name are not working.

can somebody help me fix my problem of space in name ?

Code: Select all

<td width="200" valign="top" align="left" class="black">
<script language="JavaScript" type="text/javascript" >
function changePic(fe){
var opt_key = fe.selectedIndex;
var fileName = fe.options[opt_key].value;
document.noimage.src=fileName;
return true;
}
</script>
<br>
Image :<br>
<center><select name="image" onchange="changePic(this);">
  <option>[Choisir une image]</option>
<?php

   function recur_dir($dir)
   {
       $dirlist = opendir($dir);
       while ($file = readdir ($dirlist))
       {
           if ($file != '.' && $file != '..')
           {
               $newpath = $dir.'/'.$file;
               $level = explode('/',$newpath);
               if (is_dir($newpath))
               {
                   $mod_array[] = array(
                           'level'=>count($level)-1,
                           'path'=>$newpath,
                           'name'=>end($level),
                           'kind'=>'dir',
                           'mod_time'=>filemtime($newpath),
                           'content'=>recur_dir($newpath));
			echo '<OPTION>'.$newpath.'</option>';
               }else{
  
                   $mod_array[] = array(
                           'level'=>count($level)-1,
                           'path'=>$newpath,
                           'name'=>end($level),
                           'kind'=>'file',
                           'mod_time'=>filemtime($newpath),
                           'size'=>filesize($newpath));
			echo '<OPTION value='.$newpath.'>'.$newpath.'</option>';
              }
           }
       }
       closedir($dirlist);
       return $mod_array;
   }
   
   print_r(recur_dir('Images'));
echo '</select></center>';


?>
<br>
<center><img src="peuplies-1-man-small.bmp" width="100"  id="noimage" align="center"></center>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Put quotes around the attribute value.
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Post by Peuplarchie »

where i'm not sure to understand ?
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: Space in path ?

Post by Rovas »

Instead of
Peuplarchie wrote:

Code: Select all

echo '<OPTION value='.$newpath.'>'.$newpath.'</option>';
Put

Code: Select all

echo '<OPTION value="'.$newpath.'" >'.$newpath.'</option>';
Attention some browsers don' t read corectly special characters: Safari, Internet Explorer and sometimes Firefox.
You could use functions

Code: Select all

htmlspecialchars() //or htmlentities
to display special characters.
Post Reply