Welcome Guest, Not a member yet? Register   Sign In
How to send a URL as a parameter?
#1

[eluser]rkhanna[/eluser]
I have a piece of functionality where I need to allow a user to download a file.

The user selects the file they are interested in from a file tree UI component (jqueryFileTree). I then want to send this path back as a parameter so my controller can retrieve the file from the filesystem.

However, I seem to be at a loss for how to do this given that CodeIgniter doesn't allow me pass parameters in the URL.

So right now I have a documents controller with a function as such:
Code:
function fileTreeGetFile($fullFilepath)
{
   // some code here to get the file        
}

Unfortunately I can't figure out how to get $fullFilepath to actually contain the full file path. I can't just append it to the URL because only the first segment of the file path will be captured.

Any advice on what the best practice is to proceed. Thanks.
#2

[eluser]seanloving[/eluser]
I think you are trying to let the user to browse files on the server, select a file from the server, and then download that file from the server to the client.

I can think of 3 ways...

1. Form Sumbission. You could submit $fullFilepath as form data to a controller that captures the posted data.

2. URI Segments. (I think this is the method you are asking about). Only allow user to browse for files within a certain set of folders and sub-folders. Then, from inside your fileTreeGetFile function, you can prepare the URL such as this...

http://www.yoursite.com/index.php/catche...seg2/seg3/

The controller in your main controller might look like this

Code:
function urlToPath( $seg1='', $seg2='', $seg3='', $seg4='' )
{
   // code here to re-combine the URI segments into a pathname (e.g. linux or windows)
}

You would need to include as many seg parameters as you have subfolders to browse

3. Query Strings. You can figure out how to use query strings in your URLs, something CI supports, but that I haven't played with yet.

I'm new to CI so I hope other people confirm, correct or clarify this response.

--Sean Loving
#3

[eluser]rkhanna[/eluser]
Thanks for your reply Sean.

I actually ended up going with the form post as the solution. I couldn't use the segments because I don't have control over how deep folders can become.
#4

[eluser]Phil Sturgeon[/eluser]
For next time, use this.

Code:
function urlToPath()
{
   $segments =& func_get_args();
   $filepath = implode(DIRECTORY_SEPARATOR, $segments);
}

func)_get_args() returns all arguments passed to the function as an array. DIRECTORY_SEPARATOR is just a constant added to CI recently to represent '/'.




Theme © iAndrew 2016 - Forum software by © MyBB