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
Solved

php for windows, make a writeable file

Posted on 2011-03-11
10
275 Views
Last Modified: 2012-05-11
create
a file named
data$datetime

where datetime is the current datetime

and make the file 777  writable in windows
0
Comment
Question by:rgb192
  • 4
  • 4
  • 2
10 Comments
 
LVL 3

Expert Comment

by:flubbard
ID: 35112900
I'm a little confused.  777 would be a linux type structure.  To make it writable in windows, make sure the appropriate user permissions are set for the folders.  Is this a samba share?

 - flub
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35112962
777 and any other permission settings are universal so once you set the permissions for that folder it will be writable by all platforms.
0
 
LVL 3

Expert Comment

by:flubbard
ID: 35112966
Correct, but is the file sitting on a linux box or windows box?

  flub
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rgb192
ID: 35117728
windows server 2008

I just want to make it writable
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35124534
So change the folder settings as stated above and your scripts will be able to upload and write to it.
0
 

Author Comment

by:rgb192
ID: 35131538
i would like to create a  new writable file using php
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 35132386
Ok here is how to create the new file.

$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); // this lets you open the file in write mode
// write to the file here.....
fclose($ourFileHandle); // closes the file.

Here's another example with some data written to the file.

$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData); // write to the file
$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData); // write more to the file
fclose($fh);

The file contents above will look like this when opened:

Bobby Bopper
Tracy Tanner

They are on separate lines because we added the "\n switch to the end of the $stringData to create a new line. Hope this helps.
0
 

Author Comment

by:rgb192
ID: 35150014
works to create a file and write data to file

but how to create a filename with a datetime
0
 
LVL 20

Accepted Solution

by:
Mark Brady earned 500 total points
ID: 35151421
Well it depends on exactly what you want for the date or datetime value (how you want it formatted). But here is a simple way of naming a file using datetime which should be unique but no guarantee unless you are the only person using the website. Let's assume you have a public server with lots of users. you would need to make the filename unique so best way to do that is to use a combination of a filename and a date/time. Try this:

Instead of the line
$myFile = "testFile.txt";

type this

$myFile = "yourfile_".date('y_m_d')."_".microtime().".txt";

Or it you don't need that level of precision you could simply use the date like this

$myFile = date('y-m-d').".txt";
0
 

Author Closing Comment

by:rgb192
ID: 35151475
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 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