Solved

Save Html Files to Server

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

615 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