/    Sign up×
Community /Pin to ProfileBookmark

Writing Files/Directories

Hello:

I have an online volunteer application. After the person clicks Submit, the script gets processed and I would like the results to print to a file.

I have the code working when I hard code a filename in the script. But, is it possible for a new file to be created each time a different person fills out the application?

For example, person A submits and the file appA.html is created. Now, person B submits and the file to be created is appB.html. Right now, I have appA.html hard coded in the script so this file will always be overwritten.

How can I prevent overwriting and have a new file be created?

This is the code I have. Everything above this section of code is the output of the application. Thank you for the help.

[CODE]
<?php
$html = ob_get_flush();
$file=fopen(“volunteer_app.html”, “w”);
fwrite($file, $html);
fclose($file);
?>
[/CODE]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@yinterceptMay 12.2007 — You can use variables in the file name. Since you are using full quotes, you could just create the user name by putting a user id, eg. $uid, in the file name as "app[b]$uid[/b].html". Personally, I prefer to use the dot operator to concatenate variables. It is likely that you will want to create the file name outside the call to fopen so that you can print out the file name for the user.

[code=php]<?php
// $uid is the variable for the user.
$html = ob_get_flush();
// $file_name="app$uid.html"; also works
$file_name = 'app'.$uid.'.html';
$handle=fopen($file_name, "w");
fwrite($handle, $html);
fclose($handle);
echo 'Your application is in file: '.$file_nm;
?>[/code]


The one problem with this design is that people will be able to open and view the file created by others on the system.
Copy linkTweet thisAlerts:
@focus310authorMay 12.2007 — I will give this a try and see what happens. I was hoping rather than showing a message with the filename, I would send an email saying that a new file was created. This way only the person who is supposed to receive the results will know about the file.
Copy linkTweet thisAlerts:
@TaschenMay 12.2007 — I will give this a try and see what happens. I was hoping rather than showing a message with the filename, I would send an email saying that a new file was created. This way only the person who is supposed to receive the results will know about the file.[/QUOTE]

To be honest what your suggesting could get you in a lot of trouble. Data protection legislation in Europe makes what you are proposing illegal. You must take certain proscribed steps to protect any personal data you collect. Obfuscation doesn't count.

You will need a robust login system where only user XXX (or an admin) can view personalDetails/XXX.html
Copy linkTweet thisAlerts:
@focus310authorMay 13.2007 — Hello:

Thank you for your reply. I understand what you are saying.

Do you have an alternate solution for what needs to get done? This form is an online volunteer application form. The form does require a signature. We were placing it in a file so the admin dept can print the form and schedule an interview.

Once the form is processed, how can I notify the admin dept that an application was completed, send the app info to the admin dept, and confirm to the applicant that it was sent?

The application information needs to be formatted in a specific way for the admin dept so I have to factor formatting the results before I can send it anywhere.

If you have a safer method of doing this, I am open to ideas and suggestions.

Thank you.
Copy linkTweet thisAlerts:
@TaschenMay 14.2007 — Send the responses to a database, this will also make formatting easier, and your admin department can be given access as they need it.
Copy linkTweet thisAlerts:
@focus310authorMay 15.2007 — I had a feeling you were going to say that. Do you happen to know how many fields a table can hold?
×

Success!

Help @focus310 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...