Solved

Save Html Files to Server

Posted on 2011-03-22
4
256 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 35195098
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
ID: 35196955
What is your platform windows or linux or another
0
 
LVL 2

Author Comment

by:Benji_
ID: 35197116
Its CentOS Linux :)

Best Regards
Ben
0
 
LVL 2

Author Closing Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

752 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