Solved

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

Posted on 2004-03-26
15
212 Views
Last Modified: 2006-11-17
Regarding question:
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20930341.html

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?
0
Comment
Question by:wjdashwood
  • 8
  • 6
15 Comments
 

Author Comment

by:wjdashwood
ID: 10688983
sorry i didn't explain what goes wrong. The message that missind "" in input file. It does not put anything in the "".
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10689743

>>  $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..

venkat.
0
 
LVL 6

Expert Comment

by:CosminB
ID: 10693432
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);
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 6

Expert Comment

by:CosminB
ID: 10693446
if that doesn't work post your code here
0
 

Author Comment

by:wjdashwood
ID: 10702873
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)));
     else
     {
          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);
          fclose($fp);
     }
     else
          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%">
<?php
//outputs different areas of the file
   echo '<form action="" method="post">';
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
     $cssContent = getBlock($contents, '<?php //start css ?>', '<?php //end css ?>');
     $pageContent = getBlock($contents, '<?php //start page ?>', '<?php //end page ?>');
     

     echo $cssContent;
     echo $pageContent;
     echo '</form>';
}
?>
</div>
</td></tr></table>

Thanks for the help.
0
 
LVL 6

Accepted Solution

by:
CosminB earned 450 total points
ID: 10703013
actually the error is 'missing "<?php //start css?>" in input file' (check your file's source code)
If you are trying to modify your php source code openening your file via HTTP ('http://www.d6online.co.uk/sitefiles1/demo.php';) won't work because you will only get the html code. Try
$filename='/your/html/dir/sitefiles1/demo.php';



0
 
LVL 6

Expert Comment

by:CosminB
ID: 10703022
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.
0
 

Author Comment

by:wjdashwood
ID: 10703058
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?
0
 
LVL 6

Expert Comment

by:CosminB
ID: 10703110
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
0
 

Author Comment

by:wjdashwood
ID: 10703131
what about copying the file to a temporary file? then writing it back? Would this need the ftp thing too?
0
 
LVL 6

Expert Comment

by:CosminB
ID: 10703186
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
0
 
LVL 6

Expert Comment

by:CosminB
ID: 10703196
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
0
 

Author Comment

by:wjdashwood
ID: 10703245
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.

Thanks,
H
0
 
LVL 6

Expert Comment

by:CosminB
ID: 10703271
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
0
 

Author Comment

by:wjdashwood
ID: 10703363
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

828 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