Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Problem with file

I have the following code that opens a file, the file is a php script file.

$contentFile="./" . $name . "/" . $filename;
$page_content=join("",file($contentFile));

name is a string that holds the taget dir name
fielname is a string that holds the name of the file to open and use.

the file in the test situation is called tes1.php and the contents of the file are as follows:

the test is comming
<?php

    echo "hello just testing";

?>

the test has run

$page_content is then echoed out to the screen at a later time. The problem i have is that the servere is not parsing the content of the php file that is being loaded, how do i do this thanks.
0
kplonk
Asked:
kplonk
  • 3
  • 3
  • 2
1 Solution
 
BatalfCommented:
Is there a problem just to include that file?

include($contentFile); or

require($contentFile);

Batalf
0
 
andrivCommented:
I don't know exactly what you are attempting but if you want to execute the script within another you don't want to read the file, you must include the file.  When you use the file() function you are reading line by line, it is not executed. Try:

$contentFile="./" . $name . "/" . $filename;
include("$contentfile);

If this is not what you are trying to do, please explain.
0
 
andrivCommented:
Sorry Batalf, You submitted yours while I was still typing and did not know.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kplonkAuthor Commented:
The problem with include is that the output of the include will be placed ad hock, what I need to do is buffer the output of the include statment into the var $page_content, that way i display it where and when i need to. Can this be done??
0
 
BatalfCommented:
But can't you put the include() statement wherever you want and whenever you need too?
0
 
kplonkAuthor Commented:
no, the put put of the php script swops the content of $page_content with a label in a sort of html template and then outputs that, also so there is more than one type of file that can form the conten, php is just one of many, to move the include to the corret place would mean chopping all over the place and that will be messy.

Example 11-7 in php man seems to say that

return.php
<?php

$var = 'PHP';

return $var;

?>

noreturn.php
<?php

$var = 'PHP';

?>

testreturns.php
<?php

$foo = include 'return.php';

echo $foo; // prints 'PHP'

$bar = include 'noreturn.php';

echo $bar; // prints 1

?>


$page_content = include $contentFile; should work, but it still writes the content of the file out and not store it in the var, hmm what is going on here??
0
 
BatalfCommented:
Maybe you could use the buffer-functions:

ob_start();
include("return.php");
$content = ob_get_contents();
ob_end_clean();
0
 
kplonkAuthor Commented:
Ok sorry peps sorted it, in the main code i used this code

                    $contentFile="./" . $name . "/" . $filename;
                    $page_content = include $contentFile;
                    $page_content = $page_content . addjumps();
                    return $page_content;

thanks for the include helop and also to you andriv a similer probelm you helped me with earler.

The trick is that the included script has to have a return statment and not a standard buffer out then all is well, in my example the included file has the line

return "at last i see the light!!"; and all is well.

thanks so much kieran
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now