Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Save Html Files to Server

Hi Guys,

Im wondering if anyone can help with the following problem, creating a system in PHP for the office, and we want to create documentation, the user enters the information into a HTML form and that then saves that information into a database.

The system needs to assist with the ISO 9001.

Every document created has to contain a VERSION number and a Document Reference number, what i am wanting to do as the form will never be filled out twice is store that file on the server related to the customer. Is there a way that when the staff member clicks "Save form" that we can then store that form as a File on the server somehow?

So that if we need to pull up that form it will show that it was  > FORM-001 / Version 1.

Best Regards
Ben
0
Benji_
Asked:
Benji_
  • 2
1 Solution
 
Chris StanyonCommented:
In it's most basic form, you could take the POSTed content of the form, and write that to a file. The code below will create a file if you submit a form to it that has 3 fields called DocRef, DocVersion and DocContent.

Obviously this is only a very brief and basic outline - you would need to make sure the form fields were sanitized. You may also want to add a record to a database, storing the filename along with the reference and version. You will also want to run checks to make sure that the file doesn't already exist, because the the fopen function will create a file if it doesn't already exist, or simply open for writing if it does.




//Grab the values from your form.
$DocRef = $_POST['DocRef'];
$DocVersion = $_POST['DocVersion'];
$DocContent = $_POST['DocContent'];

//Get a filename
$myFile = $DocRef . "txt";

//Create the file in the same folder as the PHP script, or exit if it can't create it.
$myFileHandle = fopen($myFile, 'w') or die("Sorry, can't open file");

//Write the info to your file
fwrite($myFileHandle, "VERSION NUMBER: " . $DocVersion . "\n\n");
fwrite($myFileHandle, $DocContent);

//Close the file handle
fclose($fh);

Open in new window

0
 
mattibuttCommented:
What is your platform windows or linux or another
0
 
Benji_Author Commented:
Its CentOS Linux :)

Best Regards
Ben
0
 
Benji_Author Commented:
Thanks for your help!
Few little tweeks to put into our system
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now