PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Sat Aug 15, 2009 3:14 am
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.
webmonkey88
Forum Newbie
Posts: 20 Joined: Fri Aug 14, 2009 4:30 am
Post
by webmonkey88 » Sat Aug 15, 2009 4:20 am
it should be include("");
and you can use file_get_contents()
cpetercarter
Forum Contributor
Posts: 474 Joined: Sat Jul 25, 2009 2:00 am
Post
by cpetercarter » Sat Aug 15, 2009 9:13 am
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.....
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Sat Aug 15, 2009 9:22 am
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.
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Sat Aug 15, 2009 9:27 am
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
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Sat Aug 15, 2009 9:52 am
Code: Select all
$file = explode("\n", file_get_contents('txtfile.txt'));
echo $file[2];
Try that.
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Sun Aug 16, 2009 2:47 am
thankX a lot this also work and reduce my problem thanX again
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Wed Aug 19, 2009 11:22 am
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
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Wed Aug 19, 2009 11:25 am
Use that code to find the filename, then use rename().
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Wed Aug 19, 2009 2:08 pm
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 ?
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Thu Aug 20, 2009 11:15 am
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
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Thu Aug 20, 2009 11:21 am
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
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Thu Aug 20, 2009 11:21 am
Have you tried giving the file 777 permissions?
mohsin360
Forum Newbie
Posts: 18 Joined: Sat Aug 15, 2009 2:39 am
Post
by mohsin360 » Thu Aug 20, 2009 11:28 am
no i dont kno abt that how to do it ?
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Thu Aug 20, 2009 11:30 am
If you're using an FTP client, you should be able right click the file and click "permissions" or "chmod" or something similar.