Welcome Guest, Not a member yet? Register   Sign In
filename whitespace repalcement in CI 2.0.2
#1

[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)?
#2

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

InsiteFX
#3

[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 )
#4

[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
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB