Welcome Guest, Not a member yet? Register   Sign In
Avoiding URL Forbidden Characters By Using urlencode()?
#1

[eluser]Matt Egan[/eluser]
Hey there! While working on my most recent project, I have encountered some odd results while combining Codeigniter's uri features with the file and download hellers...

I am creating (For my local technology fair) an application that allows groups to upload files and then distribute a URL for the project with which the other team members can upload and download files also.

Uploadih is done using the file upload class, the filename is saved into a database along with a name that the user can specify. I also save the file's upload timestamp, and the project it is associated with.

My model can generate links to the file download function of my projec controller that calls a function to force the download. This is where my problem lies. This link is formatted as follows;

..index.php/project/download/projectname/filename.txt

This model that generates the function uses PHP's urlencode() functions to replace any disslowed characters. This is my first problem, even if I encode the filename, Codeigniter interprets it as containing dissallowed characters. I'm not sure how to prevent this, is this expected behavior? If so, how can I encode the URL to not contain any dissallowed characters?

Anywho... Then, if I allow the characters that are restricted, read_file function fails to read the file. If the filename contains no strange characters, it works. I thought to replace the function with PHP's native file_get_contents, but it seems to replace the strange characters with HTML entities, and is then unable to locate the file. Again, it works of the filename does not contain anything strange. What should I do here?

I've been unable to fix these problems. I was thinking about using the security class to encode thr URL, but I kind of wanted the URL to download the file be nice and readable. In was thinking of using an auto incremented, ID field in the file database so the URL would be more like:

.../index.php/project/download/projectname/261

That might be easier, and I may end up going down this path, but I'd like to know why I'm running into these problems for future reference. Thanks so much!

By the way, I am terribly sorry for any spelling or gramatical errors, I'm in study hall typing this out on my iPhone.... 


Messages In This Thread
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 11:20 AM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 12:04 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 12:25 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 12:43 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 01:20 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 01:27 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 02:23 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 02:24 PM
Avoiding URL Forbidden Characters By Using urlencode()? - by El Forum - 02-03-2010, 07:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB