Solved

Problem with file

Posted on 2002-04-13
8
199 Views
Last Modified: 2008-03-06
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
Comment
Question by:kplonk
  • 3
  • 3
  • 2
8 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 50 total points
ID: 6939140
Is there a problem just to include that file?

include($contentFile); or

require($contentFile);

Batalf
0
 
LVL 5

Expert Comment

by:andriv
ID: 6939146
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
 
LVL 5

Expert Comment

by:andriv
ID: 6939147
Sorry Batalf, You submitted yours while I was still typing and did not know.
0
 

Author Comment

by:kplonk
ID: 6939301
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 32

Expert Comment

by:Batalf
ID: 6939313
But can't you put the include() statement wherever you want and whenever you need too?
0
 

Author Comment

by:kplonk
ID: 6939331
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
 
LVL 32

Expert Comment

by:Batalf
ID: 6939343
Maybe you could use the buffer-functions:

ob_start();
include("return.php");
$content = ob_get_contents();
ob_end_clean();
0
 

Author Comment

by:kplonk
ID: 6939353
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now