php targeting txt file somewhere else on harddrive
Moderator: General Moderators
php targeting txt file somewhere else on harddrive
hi, i am a bit of a novice when it comes to php, i was hoping someone could help me out. If i want the php script to say, fopen and fwrite into a text file that is in a completely different folder on my computer how could i do it? how would i direct the php script to it.?
Code: Select all
<?php
fopen("/home/html/tim.txt", "r");
// you can also
$file = fopen("c:\\files\\tim.txt", "r");
// notice the two \\, you must escape the backlash or use the forward slash.thanks for the post. that was really quick. I just have a couple of more questions. With the example you gave : fopen("/home/html/tim.txt", "r"); does that mean the txt file is still in a folder within the same folder as the php script? ex. folder 'A' contains: php script and the folder named 'home'.Within that folder is folder 'html' that contains 'tim.txt'. (did that make sense?)
What i want to do is this. Say I have two computers networked and the txt file is on comp1 and the php script is on comp2 how could i direct the php script to the txt file. Again thanks for the help
What i want to do is this. Say I have two computers networked and the txt file is on comp1 and the php script is on comp2 how could i direct the php script to the txt file. Again thanks for the help
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
To answer your question about the file being on the other computer, i think that you would need the text file in a shared directory, and then you can navigate to that directory and open the text file something like this:
This isn't tested but, maybe you should test it and see if it works!
Code: Select all
fopen("COMP2://SharedFiles//MyDir//MyText.txt","r");
//where COMP2 is the name of the second computer.
Last edited by Illusionist on Sun Jun 20, 2004 6:46 pm, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
a leading slash (/) tells to look from the root of the directory structure.. if you want a folder at or below the level of the php script, "some/folders/file.txt" will try to load "file.txt" which is inside the directory "folders" which is inside the directory "some", which in turn is inside the script's directory, or rather the current running directory.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I'm fairly sure that won't work Illusionist. You're using protocol structuring..
on windows networks getting to the computer named george is done like so:
"\\george\shared folder\somefile.txt"
so it'd be more like
on windows networks getting to the computer named george is done like so:
"\\george\shared folder\somefile.txt"
so it'd be more like
Code: Select all
fopen("\\\\george\\shared folder\\somefile.txt");-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
I'm actually working with os X so i'm not sure how much it differs from windows in terms of targeting files. So far i have enabled php in my 'server type' folder and have been using the browser to open execute the php scripts with the address
http://pesonalHD.local/~andreas/info/savesunset.php
I'm not sure if that is even relevant but i thought i'd drop it in there anyway
http://pesonalHD.local/~andreas/info/savesunset.php
I'm not sure if that is even relevant but i thought i'd drop it in there anyway