Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php for windows, make a writeable file

Posted on 2011-03-11
10
Medium Priority
?
280 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
[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
  • 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
Industry Leaders: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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 look for a specific file type in a local or remote server directory using PHP.
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…

688 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