We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


CosminB help with closed question re:File handling php output ...

wjdashwood asked
Medium Priority
Last Modified: 2006-11-17
Regarding question:

when I put the filename bit to:

$fileName = 'http://www.webaddress.co.uk/sitefiles1/demo.php';

then the code deosnt seem to work even though it is the exact same file as the one i tested it with where the address was just demo.php

What am I doing wrong?
Watch Question


sorry i didn't explain what goes wrong. The message that missind "" in input file. It does not put anything in the "".

>>  $fileName = 'http://www.webaddress.co.uk/sitefiles1/demo.php';

You should not put the "http://" request. If you do so, the script inside will execute and only the outpu html file will be included in your php page. so you have to say...

$fileName = '/sitefiles1/demo.php';

Included the correct path..


are there any errors or warnings??
add this line at the begining of your file and tell me if it works:
ini_set('allow_url_fopen', true);

if that doesn't work post your code here


Hi, It still doesnt seem to work. There are no error messages, just the ones I put earlierabout the missing "" in input file.

Here is my code, its pretty much what you gave me but incorporated into my code.

function getBlock($text, $startString, $endString)
     if (strpos($text, $startString) !== false && strpos($text, $endString) !== false)
          return trim(substr($text, strpos($text, $startString) + strlen($startString), strpos($text, $endString)-strpos($text, $startString)-strlen($startString)));
          if (strpos($text, $startString) === false)
               echo '<h1>Missing "',$startString,'" in input file</h1>';
          if (strpos($text, $endString) === false)
               echo '<h1>Missing "',$endString,'" in input file</h1>';
ini_set('allow_url_fopen', true);
$fileName = 'http://www.d6online.co.uk/sitefiles1/demo.php'; //at some point this needs to be altered to a variable passed in from the previous page
$contents = implode('',file($fileName));

function savecontent()
     if (is_writable($fileName))
          $cssContent = "\n//start css\n". $_POST['css']."\n//end css\n";
          $pageContent = "\n//start page\n". $_POST['page']."\n//end page\n";
          $fp = fopen($fileName, 'w');
          fwrite($fp, $cssContent);
          fwrite($fp, $pageContent);
          echo $fileName, ' is not writeable';


<table id="editor" unselectable="on" height="82%" width="100%"><tr><td>
<div id="edit" onKeyUp="reset(); markSelectedElement();" contenteditable="true" style="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 100%" onClick="reset(); markSelectedElement()"  onMouseUp="markSelectedElement();" height="100%" width="100%">
//outputs different areas of the file
   echo '<form action="" method="post">';
     $cssContent = getBlock($contents, '<?php //start css ?>', '<?php //end css ?>');
     $pageContent = getBlock($contents, '<?php //start page ?>', '<?php //end page ?>');

     echo $cssContent;
     echo $pageContent;
     echo '</form>';

Thanks for the help.
Unlock this solution and get a sample of our free trial.
(No credit card required)

the reason you are getting that error is because your sourc ecode file doesn't contain "<?php //start css ?>". Remeber that the comments from yout php sintax are not outputed to the browser.


I do have those strings in the file. I think the problem is that I have the demo.php on a different domain to the file which is calling it, hence why I put the www... bit in.

I would really like the two files to be on different domains, is there a way of changing the address so that it can find the file on another domain?

The file is found it just can read it's php source code. Also you won't be able to save the file if you open it via http
You can try reading the file using the ftp functions modify it on your server and then upload it using ftp ... but this is a little more difficult and you'll need a ftp account on the remote server


what about copying the file to a temporary file? then writing it back? Would this need the ftp thing too?

1. you can write files opened via http://
2. if you try something like copy('http://sdads/somfile.php','temp.php') you won't get php source code
3. you can get the php source code only if that file is on the same machine as your script or you if you download it using ftp or scp

sorry number 1 should be
 1. you CAN'T write files opened via http://, meaning that you can't save your file after you have edited it


could you help me do the ftp or scp thing? If you can, I'll award points for this question and open a new question and post its url here.


I'll do it but you have to know that the script will have to know the exact path of the file on the remote server (not http://somesite/somefile.php) but /path/to/somefile
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.