Can a PHP file access a text file on a different domain

liunx

Guest
I tried to have my php file read the contents of a text file on another domain but had an error. Is it the case that php files can only read text files on the same server or even same domain.<br />
<br />
Thanks,<br />
Salam<!--content-->Try setting the permissions for the text file at 777. It may work... I've never tried it. In any case, it is a bad way to do things due to security concerns. Is there any reason why you can't have the text file on the same domain?<!--content-->Originally posted by Salam <br />
Is it the case that php files can only read text files on the same server or even same domain.Yes<!--content-->Hi, actualy searching on the net I found where the problem I had was. You may find this interesting. Its in not being able to get the filesize.<br />
<br />
---------------------<br />
This will not work:<br />
---------------------<br />
$filenamee = $contentsFilePath = "http//www......./file.txt";<br />
<br />
$file = fopen ($filename, "r");<br />
$contents = fread($file, filesize($filename));<br />
<br />
can only handle files on the same domain using a relative path <br />
=============<br />
<br />
---------------------<br />
This will work:<br />
---------------------<br />
$filenamee = $contentsFilePath = "http//www......./file.txt";<br />
<br />
$file = fopen ($filename, "r");<br />
<br />
while(!feof($file)) {<br />
$contents = $contents . fread($file, 1024);<br />
}<br />
<br />
can handle files anywhere using a full path<br />
=============<br />
<br />
I found this on this page:<br />
<!-- m --><a class="postlink" href="http://www.php.net/manual/en/function.fread.php">http://www.php.net/manual/en/function.fread.php</a><!-- m --><br />
<br />
by a comment from user:<br />
rob at lbox.org<br />
on<br />
14-Nov-2002 02:28<br />
=============<br />
<br />
Regards<br />
Salam<!--content-->I would wonder if that is a sort of hack, as I don't think that you are supposed to be able to do that... Or maybe I'm thinking of something else right now, I just had a very high fever, so I'm not thinking clearly yet. :p<!--content-->Hi, if you are able to see the contents of the text file using its URL in the browser, why should not be able to read it in a program ? <br />
<br />
BUT here is the question I have for you: <br />
Is it safe to put the PHP program I wrote in a directory accesable to useres using its URL. In other words is there any way for others to see the class and methods I wrote ? or I should put it on a directory that is not accessable and make another small PHP file that calles the methods in the one including the actual code.<br />
<br />
Salam<!--content-->Pyro, I can't thank you enough for you help. I did not hear of PHP when I posted my first question on this forum. you made me the basic PHP code that evolved to a 600 line program. I am real lucky that you led me to PHP since it uses Java syntax which I know good.<br />
<br />
Salam<!--content-->Since PHP is executed server side, it is quite safe to put it in a directory that is accessible on the internet. If users try to Download <!--more--> the file, they will simply get the output of the file, and not the file itself.<br />
<br />
Yes, PHP is quite easy to pick up if one has knowledge of javascript. It is syntactically quite close, you just need to learn the commands/quirks of the language...<!--content-->Hi, actually I ment the Java programing language not Java Script. PHP uses mostly the exact syntacs of Java (not Java Script). There is even a similarity in some of the function libraries like handeling files and to a degree strings :)<!--content-->I don't know any Java, but my above statement was correct as well, PHP and javascript are syntactically close. :D It's nice to hear that Java and PHP are close, incase I ever decide to learn Java...<!--content-->Hi, the similarity between PHP and Java is far more than the similarity between PHP and Java Script :)<br />
<br />
Salam<!--content-->
 
Back
Top