views:

44

answers:

3

hi.

dealing with php/html/javascript.

i'm trying to figure out a good/best approach to allowing a user to download a file. i can have the traditional href link, that interfaces with the back end php app to download the file.

however, i want to have the app display some sort of dialog/alert if the user isn't able (basedon acl/permissions) to download the file... does this have to ba an ajax thing, as i don't want to do a page refresh...

thoughts/comments/pointers to code samples are appreciated.

thanks.

-tom

hi... more data/information.

in my test, i send the userID/fileID via the query to the backend php.

the app then confirms the user is the user for the file, and that the user has the rights to access the file. the query data is matched against data in the db for the user/file combination.

so the last/critical check occurs on the back end.

hope this gives a bit more insight into what i'm looking to do/accomplish.

thanks

-tom

+1  A: 

AJAX could be a good technology to use if your looking for a work-around for the page not refreshing but it doesn't have to be your only option.

Another option without requiring AJAX, which might be cumbersome depending on how your project is design, is to enable or disable features depending on the user's authentication level.

As a simple example, enable features only related to Administrators and disable Administrator features for normal users.

You don't necessarily have to enable/disable features, you could also decide before the user clicks on links whether or not he/she has rights to do-so.

With more information on how your project is laid out, we can provide more concise answers.

Anthony Forloney
A: 

The easiest method would be to return a HTTP response code of 401 ("Unauthorized"). This will cause your web server to display the 401 error page, which you can modify to fit your design.

Or, if you are using AJAX, then you can check for a 401 response code and pop up a nice alert for them without taking them to a different page.

Sam Bisbee
A: 

ya ajax is will best one to do....go with ajax

dpaksp