CodeIgniter Forums
filename whitespace repalcement in CI 2.0.2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: filename whitespace repalcement in CI 2.0.2 (/showthread.php?tid=42400)



filename whitespace repalcement in CI 2.0.2 - El Forum - 06-06-2011

[eluser]murphybr[/eluser]
sorry but I am having issues with this.

I have code that is listing all files in a directory with link to download.

My issue, any file with whitespace ie. Murphy Test File.txt when linked is only showing pathway/Murphy

Code:
while($entryName = readdir($myDirectory))
{
  $dirArray[] = $entryName;
}


closedir($myDirectory);

Is there some kind of library or helper that has a function that could take those white spaces in the file name and for reading and linking purposes replace them with \(space)?


filename whitespace repalcement in CI 2.0.2 - El Forum - 06-06-2011

[eluser]InsiteFX[/eluser]
Code:
$dirArray[] = str_replace(' ', '_', $entryName);
You would need to reverse it to link to the files.

InsiteFX


filename whitespace repalcement in CI 2.0.2 - El Forum - 06-07-2011

[eluser]murphybr[/eluser]
that didnt work.

href is still breaking instead of showing ip/path/to/file/Murphy
it is showing the link as ip/path/to/file/Murphy\

coudl href be breaking the whitespace or \ issue.

my dirArray[] is echoing as follows when i type a print_r($dirArray)after building the dirArray

Array ( [0] => . [1] => Murphy File Transfer.docx [2] => upload_test.txt [3] => .. [4] => Murphy_Test.xls [5] => job_interview_suc.pdf )

after str_replace it appears as follows

Array ( [0] => . [1] => Murphy\ File\ Transfer.docx [2] => upload_test.txt [3] => .. [4] => Murphy_Test.xls [5] => job_interview_suc.pdf )


filename whitespace repalcement in CI 2.0.2 - El Forum - 06-07-2011

[eluser]InsiteFX[/eluser]
You can try this:
Code:
$entryName = str_replace(' ', '_', $entryName);
$entryName = rtrim($entryName, '\');
$dirArray[] = $entryName;
If it's adding a '\' then it could be coming from some place else!

InsiteFX


filename whitespace repalcement in CI 2.0.2 - El Forum - 06-07-2011

[eluser]murphybr[/eluser]
my apologies instead of '_' i put '\ '.

upon further reading i noticed codeigniter reads white space as %.2.0(without the periods) so i used the following code:

Code:
$dirArray[] = str_replace(' ', '%.2.0 ', $entryName);

it now shows the link correctly. I used the str_replace in a loop to remove the %.2.0 to create the output name.

Thank you very much for your assistance.