carriker Posted June 9, 2006 Share Posted June 9, 2006 I'm pretty new to php, so I think this is a pretty simple question. Basically I've got a script that takes in some post data and uses that information to open or create a new txt file, write some text, and save it to a specified location on the hard drive. That part works just fine. The machine that's running php/apache is also on a LAN and I would like to write the same txt file to a different computer on the network. I've tried a couple of times but haven't gotten this to work. So my first question: is there any reason this can't work? And my second question: if it's possible, what should the file path look like. The file path would normally be "\\OtherComputer\C\TextFiles\SomeTextFile.txt", but I know php likes forward slashes instead of back slashes. However, if I just replace the forward slashes with back slashes it doesn't work.Thanks in advance,--carriker Quote Link to comment https://forums.phpfreaks.com/topic/11583-writing-a-text-file/ Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 The reason php likes forward slashes instead of backslashes is that the backslash is usually used as an escape character (despite this, Microsoft still decided to use it in their file paths through their infinite wisdom). So if you put it in double quotes like "\\path\to\new\dir" PHP will think the \n is a new line character. A way to solve it would be to put the path in single quotes like '\\path\to\dir' however you said replacing them with forward slashes still didn't work. It should normally as PHP can change them to backslashes if running on Windows which suggests there's something else wrong, I don't know how PHP handles filesystems on other networks. It may have to connect to another server running on the other computer or you may have to assign the other computers drive names like G: and F: and then use those. Quote Link to comment https://forums.phpfreaks.com/topic/11583-writing-a-text-file/#findComment-43647 Share on other sites More sharing options...
craygo Posted June 9, 2006 Share Posted June 9, 2006 I have no problem changing the slashes. I run php from my windows box and it seems to interperateC:\Inetpub\wwwroot AND C:/InetPub/wwwroot As the same thing.So just use "/" instead of the windows "\" and you should be fine.Ray Quote Link to comment https://forums.phpfreaks.com/topic/11583-writing-a-text-file/#findComment-43691 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 [!--quoteo(post=381905:date=Jun 9 2006, 10:49 AM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Jun 9 2006, 10:49 AM) [snapback]381905[/snapback][/div][div class=\'quotemain\'][!--quotec--]I have no problem changing the slashes. I run php from my windows box and it seems to interperateC:\Inetpub\wwwroot AND C:/InetPub/wwwroot As the same thing.So just use "/" instead of the windows "\" and you should be fine.Ray[/quote]I did mention that here:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]however you said replacing them with forward slashes still didn't work. It should normally as PHP can change them to backslashes if running on Windows[/quote] and carriker also said he'd tried changing them to forward slashes already here:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]However, if I just replace the forward slashes with back slashes it doesn't work.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/11583-writing-a-text-file/#findComment-43695 Share on other sites More sharing options...
craygo Posted June 9, 2006 Share Posted June 9, 2006 How many PC's do you plan on writing this file to. If you are an admin the only way around writing a file to another computer would be to map a drive on the web server to the remote PC. That way the forward slashes would work no problem. Only problem I see here would be making sure the permission are setup correctly.I overlooked him trying to connect to a remote computer by using the UNC. My BAD. Using forward slashes from drive letters works no problem.Ray Quote Link to comment https://forums.phpfreaks.com/topic/11583-writing-a-text-file/#findComment-43699 Share on other sites More sharing options...
carriker Posted June 9, 2006 Author Share Posted June 9, 2006 I did a test with fopen.if I use fopen with "//OtherComputer/C/test.txt" I get a "Permission Denied" warning.if I use fopen with "f:/test.txt" where f is the mapped network drive \\OtherComputer\C\ , I get a file does not exist warning.So it seems like the first option is better, but I'm not sure how to set the appropriate permissions on a windows machine. I've already allowed sharing so anyone on the network to change the files on that drive.Thanks again,--carriker Quote Link to comment https://forums.phpfreaks.com/topic/11583-writing-a-text-file/#findComment-43715 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 chmod 0777 //OtherComputer/C/ from the command line or the same command in exec() Quote Link to comment https://forums.phpfreaks.com/topic/11583-writing-a-text-file/#findComment-43742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.