Page 1 of 2
php include code problem
Posted: Sat Aug 15, 2009 3:14 am
by mohsin360
my php include code is running very well by which i can impot contents of a .txt and print store in a same directory.
my code is
this
-----------------------------------------------------------------
but i want to include a .txt file store in another directory like the address of the file is
http://www.somesite.com/textfile.txt. is there some way by include or other than include function to include a file hosted on some server plz help.
Re: php include code problem
Posted: Sat Aug 15, 2009 4:20 am
by webmonkey88
it should be include("");
and you can use file_get_contents()
Re: php include code problem
Posted: Sat Aug 15, 2009 9:13 am
by cpetercarter
To be totally pedantic, you don't need to use brackets with 'include' (or 'require'), because 'include' is a statement, not a function. It's just one of those useless bits of information that clutter my brain.....
Re: php include code problem
Posted: Sat Aug 15, 2009 9:22 am
by jackpf
include is a construct, just like echo, or...return. You don't need to use parenthesis.
Anyway, you can use fopen(), file_get_contents() curl, sockets, or include if you have allow url include turned on.
Re: php include code problem
Posted: Sat Aug 15, 2009 9:27 am
by mohsin360
thankz to u all for answering my question.
i have another question plz help me again.
problem is that file_get_contents is work well and reflects all contents in my txt file.
but if there is any possiblity that file_get_contents or any other function reflects only one line of a txt file likemy txt file is something like this
and i want to only get line no 3 which contains content[789]
is there some way
Re: php include code problem
Posted: Sat Aug 15, 2009 9:52 am
by jackpf
Code: Select all
$file = explode("\n", file_get_contents('txtfile.txt'));
echo $file[2];
Try that.
Re: php include code problem
Posted: Sun Aug 16, 2009 2:47 am
by mohsin360
thankX a lot this also work and reduce my problem thanX again
Re: php include code problem
Posted: Wed Aug 19, 2009 11:22 am
by mohsin360
thank X for all reply
sorry if i ask too many questions but i have 1 more
is there any possibility that a php page can automatically rename itself from a line of text from a remote .txt file ? i know its tricky
Re: php include code problem
Posted: Wed Aug 19, 2009 11:25 am
by jackpf
Use that code to find the filename, then use rename().
Re: php include code problem
Posted: Wed Aug 19, 2009 2:08 pm
by mohsin360
use what code to find file name?
i read about it at php official web and find that this code used to rename some file other than the file containing code ?
Re: php include code problem
Posted: Thu Aug 20, 2009 11:15 am
by mohsin360
i uploaded two files in
http://www.myweb.com/mohsin3 named index.php containing code
Code: Select all
<?php
rename("index2.php","index3.php");
?>
and another file index2.php to rename but when i try to visit page it shows something like this
Code: Select all
Warning: rename(index2.php,index3.php) [function.rename]: Permission denied in /home/jcipakis/public_html/mohsin3/index.php on line 2
Re: php include code problem
Posted: Thu Aug 20, 2009 11:21 am
by mohsin360
i tried another hosting service it also shows something like this
Code: Select all
Warning: rename(index2.php,index3.php) [function.rename]: Permission denied in /home/a2992386/public_html/mohsin3/index.php on line 2
this server have php version 5.2.9
Re: php include code problem
Posted: Thu Aug 20, 2009 11:21 am
by jackpf
Have you tried giving the file 777 permissions?
Re: php include code problem
Posted: Thu Aug 20, 2009 11:28 am
by mohsin360
no i dont kno abt that how to do it ?
Re: php include code problem
Posted: Thu Aug 20, 2009 11:30 am
by jackpf
If you're using an FTP client, you should be able right click the file and click "permissions" or "chmod" or something similar.