Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php for windows, make a writeable file

Posted on 2011-03-11
10
Medium Priority
?
282 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
Technology Partners: 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!

 

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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

926 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