1

I'm currently using CodeIgniter. It seems i cannot get the complete value of a query string that has this value:

mywebsite.com/home?path=Announcement/1036_Write-up Montessori J & D 2017]1504509916.pdf

I tried using $_GET['path'] and $this->input->get('path') but both didn't work.

Actual Behavior: path only has this value: Announcement/1036_Write-up Montessori J

Expected Behavior: path should have the entire path value: Announcement/1036_Write-up Montessori J & D 2017]1504509916.pdf

B. Desai
  • 16,414
  • 5
  • 26
  • 47
Mykel Aballe
  • 235
  • 1
  • 4
  • 15
  • 2
    Are you typing that URL in? However it's being generated, you need to URL encode the value. It should be `Announcement%2F1036_Write-up%20Montessori%20J%20%26%20D%202017%5D1504509916.pdf`. The most important part is encoding the ampersand from `&` to `%26` – Phil Sep 06 '17 at 04:22
  • 2
    You need to `encode` your url while you redirecting it. In URL `&` separate params thats why you are not getting entire value – B. Desai Sep 06 '17 at 04:23
  • I'd also recommend using safer filenames in and of themselves. If your file is really called `1036_Write-up Montessori J & D 2017]1504509916.pdf`, it seems strange to have both spaces and underscores. I've also never seen a `]` in a filename before. Rename your file to something like `1036_writeup_montessori_j_and_d_2017_1504509916.pdf` and you won't encounter encoding problems ;) – Obsidian Age Sep 06 '17 at 04:26
  • the value is actually from a user. i cannot control how they will name the file – Mykel Aballe Sep 06 '17 at 04:34
  • how should i do the encode? – Mykel Aballe Sep 06 '17 at 04:35
  • i tried urldecode(urlencode($path)) - works in desktop browser but not in mobile browser. The value stops at the letter "J" – Mykel Aballe Sep 06 '17 at 04:39
  • just used urlencode($path). why you using for 2 times. – Chaitanya Desai Sep 06 '17 at 05:54
  • You can use current_url() function to get the URL and then use basename() function to get the file name. – Chaitanya Desai Sep 06 '17 at 05:56
  • 1
    try urlencode(string) – Ranjith M Sep 06 '17 at 06:06

0 Answers0