?
Solved

Simple time reservation site . . . . Can PHP use flat files?

Posted on 2009-05-05
8
Medium Priority
?
244 Views
Last Modified: 2013-12-12
I want to create a trivial page where visitors can enter simple info (reserving a date and time slot for my service - dog walking ! )
Without an SQL interfaced DB, can I save user info and selections in another way, say on a flat file?
I dont need GB of space. Is there a simple site web host? with domain registration? I need a trivial PHP page that need only remember dates my users want my service.
Ideas?
I do have an always-on machine. Could I link that to a domain, with some php and simple db?
Trivial?

0
Comment
Question by:beavoid
[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
  • 4
  • 3
8 Comments
 
LVL 4

Assisted Solution

by:bleach77
bleach77 earned 150 total points
ID: 24311131
1. Yes, you can save it in a flat file. Database are mostly use for big data for easier search.
   Use fread and fwrite function.

2. You can link the domain to your computer. Given that you have a fix IP. Otherwise you have to change the IP of your site everytime your IP change. But I guess it will be much more easier to use a hosting site as it does not cost a lot nowadays. You can google for a cheap hosting :)
0
 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 1350 total points
ID: 24312576
Try this sample code to get used to it.  I would however recommend a bit more advanced reading up on .csv plain text databases.  .csv are basicly plain text spread sheets that can be read by excel etc.  Reading and saving and updating CSV format is much easier in the long run than coming up with your own format for your text files.

PHP has functions for managing csv files... just try a Google search for some tutorials and you will be up and running really fast.

Also Bleach is right - there are good reasons to use a web host - not just very cheap but also they manage uptime, security and etc for you so you don't need to worry about it.  It's probably the best idea for serving a website as the service is more high tech and safer than serving from your own home or office in most circumstances.
$file = "full/path/to/your-text.txt";
 
$fp = fopen ($file,"r"); //open file for reading
$Data = fread($fp,filesize($file));  // read data save as $Data variable
fclose ($fp);
 
$fp = fopen ($file,"w+"); //open file for writing (and create the file if it not exists!)
fwrite($fp,$Data));  // save data to the file
fclose ($fp);

Open in new window

0
 

Author Comment

by:beavoid
ID: 24370831
Where will $file reside?
In the site's file directory, with the PHP files?
0
Industry Leaders: 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!

 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 1350 total points
ID: 24375123
Hi,

$file = "full/path/to/your-text.txt";

- The file can be wherever you want it to be *inside* your web directory... it could be along side your php files but it might be better to create another sub folder - perhaps "data/myfile.csv" or similar.

Cheers!
0
 

Author Comment

by:beavoid
ID: 24381310
So, i I get a google web-space, this file should be right there with index.php?
0
 
LVL 3

Assisted Solution

by:NIPPLES
NIPPLES earned 1350 total points
ID: 24387060
Yes you can put it there if you like so long as wherever you put it, it must match the path in your code :)
0
 

Author Comment

by:beavoid
ID: 24400883
Would you go for the tab spaced simple .txt DB for a trivial site like this?
I havent used .csv yet and the .txt should be fine.

I know all about CS 200 whitespace DB's

Does the $data up there return the entire file specified?
How do I delimit the  $data  tokens?
0
 
LVL 3

Accepted Solution

by:
NIPPLES earned 1350 total points
ID: 24401449
Hi there,

CSV is plain text - just with delimiters.  A standard CSV will use something like...

"text","more text","even more text"
"text","more text","even more text"
"text","more text","even more text"
"text","more text","even more text"

You can also use a tab as the delimiter... to work with tabs in PHP they are similar to new lines ...

/r/n = new line
/t = tab

Finally yes, in the example above, $data variable contains the entire files text.  For much larger text files you may want to use a recursive file read with a buffer, maybe something like...


$CompleteData = "";
$ConnectionString = "path/to/your/file.txt";
 
$handle = @fopen($ConnectionString, "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 9096);
	$CompleteData .= $buffer;
    }
    fclose($handle);
}
print $CompleteData;

Open in new window

0

Featured Post

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

777 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