Solved

php for windows, make a writeable file

Posted on 2011-03-11
10
268 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn how to count occurrences of each item in an array.

758 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

18 Experts available now in Live!

Get 1:1 Help Now