Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-05-05
8
Medium Priority
?
248 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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

604 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