php include code problem
Moderator: General Moderators
Re: php include code problem
ya i find it and do it
Re: php include code problem
Code: Select all
<?php
$path="/home/jcipakis/public_html/mohsin3/";
$msn=basename($path,".php");
echo $msn;
?>this code tells me only directory but not the filename
my file store in public_html/mohsin3 and name of my file is index3.php
when i visit the page it prints mohsin3 the last folder of my dir ?
what can i do?
Re: php include code problem
I don't really understand what you're trying to do, but to include files from an absolute path, you can do this:
Code: Select all
include $_SERVER['DOCUMENT_ROOT'].'/index3.php';Re: php include code problem
i have a file A and name of file a is index.php
i want it to find its own name and if its name is index.php it changes it to index3.php and if it find its own name index3.php it will dont doany thing
i want it to find its own name and if its name is index.php it changes it to index3.php and if it find its own name index3.php it will dont doany thing
Re: php include code problem
you can use the __FILE__ magic constant that gives you the current complete path + file name.
Code: Select all
$file = basename(__FILE__);
if( $file == 'index.php' ) {
header('Location: index3.php');
}
Re: php include code problem
i tried this
the two files newname.txt have text [new.php]
and oldname.txt have text [old.php]
but does not work i think there is some problem about names
it shows me
new.phpold.php
Warning: rename(1,1) [function.rename]: No such file or directory in /home/a2992386/public_html/mohsin4/index.php on line 9
Code: Select all
<?php
$filename= basename(__FILE__);
$newname= include "newname.txt" ;
$oldname= include "oldname.txt" ;
if($filename != $newname){
rename("$oldname","$newname");
}
else{
header('Location: $newname');
}
?>and oldname.txt have text [old.php]
but does not work i think there is some problem about names
it shows me
new.phpold.php
Warning: rename(1,1) [function.rename]: No such file or directory in /home/a2992386/public_html/mohsin4/index.php on line 9
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: php include code problem
If you write
$newname will have the value 1 if the include is successful or 0 if it is not successful. It will not contain the text of whatever is written in "newname.txt". To do this, you need to open and read "newname.txt" into $newname.
Code: Select all
$newname = include "newname.txt";
Re: php include code problem
Code: Select all
<?php
$filename= basename(__FILE__);
$newname= readfile("newname.txt");
$oldname= readfile("oldname.txt");
if($filename != $newname){
rename("$oldname","$newname");
}
else{
header('Location: $newname');
}
?>it shows
new.phpold.php
Warning: rename(7,7) [function.rename]: No such file or directory in /home/a2992386/public_html/mohsin4/index.php on line 9
Re: php include code problem
so what can i do now ?
and error is not in
header statement it shows in rename statement
and error is not in
header statement it shows in rename statement