Solved

Save Html Files to Server

Posted on 2011-03-22
4
253 Views
Last Modified: 2012-05-11
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
Comment
Question by:Benji_
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
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
 
LVL 11

Expert Comment

by:mattibutt
Comment Utility
What is your platform windows or linux or another
0
 
LVL 2

Author Comment

by:Benji_
Comment Utility
Its CentOS Linux :)

Best Regards
Ben
0
 
LVL 2

Author Closing Comment

by:Benji_
Comment Utility
Thanks for your help!
Few little tweeks to put into our system
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now