|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
php5 - Html form to secure excel document
I have an html form that posts the results to an excel csv file.
In FrontPage I could put the csv file in a _private folder and it would not be accessible on the internet. I am now using dreamweaver and would like to do the same sort of thing with the csv file. I have tried moving the csv file to another folder (ei: $filename = "_private/formresults.csv";) but it doesn't work. Any ideas? $firstname = $_POST['FirstName']; $lastname = $_POST['LastName']; $email = $_POST['email']; $address = $_POST['Address']; $city = $_POST['City']; $state = $_POST['State']; $phone = $_POST['Phone']; $zip = $_POST['Zip']; $military = $_POST['Military']; //now we open the file using the a flag, this will create the file if //it does not exist, and puts the pointer(where it starts writing) at the //end of the file $filename = "formresults.csv"; $handle = fopen($filename, 'a'); //now we prepare our string to be added: $string_to_add = "$firstname,$lastname,$email,$address,$city,$state, $phone,$zip,$military" . "\n"; fwrite($handle, $string_to_add); //now close the file fclose($handle); |
|
#2
|
|||
|
|||
|
You should do a Google search for "Restricting directory access" for whatever server type you are using, that should give you an idea of how to do it.
|
|
#3
|
|||
|
|||
|
Html form to secure excel document
Quote:
I will do some research on that. Thanks for pointing me in the right direction. |
|
#4
|
|||
|
|||
|
what type of server do you use? In apache it could be as simple as putting a file named .htaccess with nothing more than "deny from all" in any folder you want to deny access to. PHP would still have access to said folder, just people can't visit it through the web server.
|
|
#5
|
|||
|
|||
|
Quote:
I just spoke to our web server company and we are on appache. They are setting up the htaccess for me now. I don't know anything about that but will learn soon. Will the code have to be changed for me to hit the spreadsheet? You guys are great! |
|
#6
|
|||
|
|||
|
the shouldn't have to be changed unless there is a different folder you want to save it to. like I said before, you just need to put a .htaccess file in the folder and put nothing but "deny from all" (no quotes) inside that file. that will do exactly what it says, deny access to all people who try to access the folder through the website. Other programs like PHP will still have full access to anything in the folder because it doesn't have to go through apache to get to there.
.htaccess files are just a way of setting config options for apache on a directory basis. Generally any folders with a .htaccess file and any subdirectories under that folder will be affected by the file. They are mostly used to URL rewriting which gets you the clean URLs that you see on most sites nowadays. |
|
#7
|
|||
|
|||
|
Html form to secure excel document
Quote:
I'm still not populating the spreadsheet so I must be doing something wrong. The .htaccess page the web server company set up is password protected: AuthType Basic AuthName "Admin Access" AuthUserFile /web/acl/deprez.pwd Require valid-user It is in a folder called excel I added to this folder my php page and the csv spreadsheet. The forms action is "excel/clientprofile2.php" Do I need to put anything on the form or php page indicating the use of the htaccess page? |
|
#8
|
|||
|
|||
|
Html form to secure excel document
Quote:
This was wrong. Don't know what I was thinking. The form points to the php file not located in the excel folder. The php file points to the excel folder which houses the csv file. (excel/filename.csv) Unfortunately it doesn't populate the spreadsheet. Even if I use a folder without htaccess the code doesn't seem to want to populate the csv. It only seems to work if they are on the same level. Any clues? |
|
#9
|
|||
|
|||
|
try something like this:
PHP Code:
|
|
#10
|
|||
|
|||
|
Quote:
I get an http 500 error from that code. |
|
#11
|
|||
|
|||
|
It worked fine on my server. a 500 error is "A generic error message, given when no more specific message is suitable". you should look to see if there is an error log somewhere and try to resolve whatever problem it is displaying. You also might want to double check permissions to make sure that the folder you want to save the file in is writable to the web server.
|
|
#12
|
|||
|
|||
|
Quote:
Thank you for all of your help. I changed the permissions on my spreadsheet to 777 and now the form is perfect. I am ready to convert the rest of the forms on the website. What a relief. Thanks again Colleen |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > php5 - Html form to secure excel document |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|