Solved

php for windows, make a writeable file

Posted on 2011-03-11
10
270 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
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.

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now