Solved

Save Html Files to Server

Posted on 2011-03-22
4
255 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 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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 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